此NullPointerException的原因是什么JAVA

此NullPointerException的原因是什么JAVA,java,nullpointerexception,Java,Nullpointerexception,我目前正在处理一个项目,收到一个NullPointerException,但找不到异常的位置/源。 我使用的代码是: public static void AccessAccount(){ try{ System.out.println("Enter your card number to access your account:"); int CardNumber = sc.nextInt(); String CardNumberStr

我目前正在处理一个项目,收到一个
NullPointerException
,但找不到异常的位置/源。 我使用的代码是:

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());
    }
}

如果有人能帮我找到问题的根源,那就太好了。

可能您没有反对该文件,请检查fileReader变量的状态。如果为空,则必须检查文件的路径

第146行看起来是一个很好的起点。那是哪一行?调试时,哪个对象是
null
?您希望在哪里初始化该对象?嗯,问题的根源是第146行。(提示:学习如何调试)。NPE的所有需要都在规范的答案中。边注:你应该考虑根据这个行一致命名你的变量。code>,它写在
String[]PinSearch={}之前,正在返回
null
。由于没有更多的内容可从文件中读取,这就是为什么
do-while
循环首先结束的原因。因此,似乎
第144行
是将
null
赋予
变量,并在
146行
上使用该
null
引用调用
split
java.lang.NullPointerException
    at VirtualATM.AccessAccount(VirtualATM.java:146)
    at VirtualATM.RegisterNewCard(VirtualATM.java:95)
    at VirtualATM.main(VirtualATM.java:35)