JOptionPane中的NullpointerException

时间:2015-09-26 17:45:04

标签: java nullpointerexception joptionpane

****它在JOptionPane代码中抛出NullPointerException,如下所示。****

public static void main(String[]args){


    String[] options={"Do it again?", "Exit"};
    int response=0;
    int indexOfZip;
    do{
        try{

        String dataStr=JOptionPane.showInputDialog("Enter a zip code");


        if(dataStr!=null){
             while (k<i){
                 if (place[k].equals(dataStr)){

                 indexOfZip=k;
                     k++;
                 }

             }
             int data=Integer.parseInt(dataStr);
             response=JOptionPane.showOptionDialog(null,
                           "You asked me to search for zip code:"+dataStr+"The zip code "+dataStr+" belongs to"+place[k].getTown()+","+place[k].getState()+"Do you want me to search again?",
                           "results",

                           JOptionPane.YES_NO_OPTION,
                           JOptionPane.QUESTION_MESSAGE,
                           null,
                           options,options[0]);


             System.out.println("You asked me to search for zip code:"+dataStr);
             System.out.println("The zip code "+dataStr+" belongs to"+place[k].getTown()+","+place[k].getState());
             System.out.println("Do you want me to search again?");

        }


        }catch(NumberFormatException e){
        JOptionPane.showMessageDialog(null,"Bad Numeric String, try again.", "Input Error",JOptionPane.ERROR_MESSAGE);

         }
    }while(response==0);
    if (response!=0){
       System.out.print("No");
       System.out.println("Good Bye!");
    }



    }

终端表示此行的例外情况     响应= JOptionPane.showOptionDialog(NULL,

但我在这里看不出任何错误,因为“响应”在之前被初始化了。

1 个答案:

答案 0 :(得分:0)

看起来window.onload = -> $('.box').find('img').each -> imgClass = if @width / @height > 1 then 'wide' else 'tall' $(this).addClass imgClass return return 必须是place[k], 和null触发place[k].getTown()。 在调试器中观察NullPointerException的值(或添加打印语句)。