【发布时间】:2015-12-28 07:11:06
【问题描述】:
我遇到了这个异常
线程“main”中的异常 java.lang.NumberFormatException: null
在 java.lang.Integer.parseInt(Integer.java:542)
在 java.lang.Integer.parseInt(Integer.java:615)
在 Test.main(Main.java:10)
代码:
import java.util.*;
import java.io.*;
class Test {
public static void main (String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a[]=new int[10],flag=1;
System.out.println("Enter The Nos.");
for(int i=0;i<=9;i++)
a[i]=Integer.parseInt(br.readLine());
int i=0;
do{
if(a[i]!=42)
System.out.println(a[i]);
else{ flag=0;break;
} i++;
}while(flag==1);
}
}
它在 Eclipse 上运行良好,但在其他 IDE 上,它给出了这个异常。
【问题讨论】:
-
你能告诉我你对这个程序的意见吗?
-
异常信息已经够清楚了。你有什么不明白的?
-
试试我回答中的代码。这应该可以解决问题。
-
在尝试将其转换为整数之前尝试打印出“br.readLine()”的结果。这将为您提供有关如何修复程序的线索。
标签: java arrays exception numberformatexception