私は、ユーザーからオプションとしてint入力を受け取るJavaプログラムを作成しています。入力に基づいて、プログラムは、私は、コードを実行すると、それは次のようなエラーにScannerの問題
Exception in thread "main" java.lang.NullPointerException
at lab1.EchoClient.main(EchoClient.java:25)
を与える異なるmethod.Butに行きます私のコードの行25で
private Scanner reader;
public static void main(String[] args){
EchoClient c = new EchoClient();
int option;
System.out.println("Welcome");
System.out.println("Select one of the following options:");
System.out.println("1 - Iterative Server");
System.out.println("2 - Concurrent Server");
System.out.println("3 - Exit");
option = c.reader.nextInt(); // Line No 25
switch(option){
case 1:
c.iterative();//calls the iterative method
break;
case 2:
//some method
break;
case 3:
System.out.println ("bye bye");
break;
}//end of switch()
}//end of main()
public void iterative(){
String address;
String ip="";
try{
System.out.println ("Please enter your correct ip address");
BufferedReader getip= new BufferedReader (newInputStreamReader(System.in));
ip=getip.readLine();
}
catch (IOException error){
System.err.println("Error occured");
}
の一部はラインです:オプション= C .reader.nextInt();
あなたの手助けをしたい人が多くの時間を無駄にしないように、ソースコードをより良い方法で整形してみてください。 – KNU