-2
현재 프로젝트를 진행 중이고 NullPointerException
이 발생하여 예외의 위치/소스를 찾을 수 없습니다. 내가 사용한 코드는 다음과 같이 주어진이 NullPointerException의 원인은 무엇입니까? - Java
public static void AccessAccount(){
try{
System.out.println("Enter your card number to access your account:");
int CardNumber = sc.nextInt();
String CardNumberStr = Integer.toString(CardNumber);
boolean Exist = false;
String LineNo;
String [] CardNum = {};
int Counter;
FileReader fileReader = new FileReader("VirtualATM.txt");
BufferedReader bufferedReader = new BufferedReader(fileReader);
line = bufferedReader.readLine();
CardNum = line.split("\\s+");
do{
for(Counter = 0; Counter < CardNum.length; Counter++){
LineNo = CardNum[Counter];
if(LineNo.contains(CardNumberStr)){
Exist = true;
}
else if(Counter == CardNum.length){
Exist=false;
}
}
//add this line to read another line of the file
//and check if it exists
line = bufferedReader.readLine();
}while(!Exist && line != null);
System.out.print("Enter your pin: ");
int EnterPin = 0000;
try{
EnterPin = sc.nextInt();
}catch(InputMismatchException e){
e.printStackTrace();
System.out.println(e.getMessage());
}
boolean pinTrue = false;
String EnteredPin = Integer.toString(EnterPin);
line = bufferedReader.readLine();
String [] PinSearch = {};
PinSearch = line.split("\\s+"); /**** LINE 146 IS HERE***/
do{
for(int search = 0; search < PinSearch.length; search++){
String SearchForPin = PinSearch[search];
if(SearchForPin.contains(EnteredPin)){
pinTrue = true;
}
else if(search == PinSearch.length){
pinTrue = false;
}
}
line = bufferedReader.readLine();
}while(pinTrue == false && line != null);
bufferedReader.close();
}catch(FileNotFoundException e){
e.printStackTrace();
System.out.println(e.getMessage());
}catch(IOException e){
e.printStackTrace();
System.out.println(e.getMessage());
}
}
오류는 다음과 같습니다 누군가가 나에게 문제의 원인을 찾을 수 있도록 할 수 있다면
java.lang.NullPointerException
at VirtualATM.AccessAccount(VirtualATM.java:146)
at VirtualATM.RegisterNewCard(VirtualATM.java:95)
at VirtualATM.main(VirtualATM.java:35)
것은, 그 위대한 것입니다.
선 146을 시작하는 것이 좋습니다. 그게 어떤 선 이니? 이것을 디버깅 할 때 어떤 객체가'null'입니까? 그 객체가 어디에서 초기화 될 것으로 기대합니까? – David
어, 문제의 원인은 146 행입니다. (힌트 : 디버깅하는 방법에 대해 자세히 알아보십시오.) –
NPE에 대해 알아야 할 모든 것이 표준 답변입니다. –