日期:2014-05-20  浏览次数:20725 次

异常问题,程序本身没错误
package   test.io;

import   java.io.BufferedReader;
import   java.io.IOException;
import   java.io.InputStreamReader;

public   class   testaaa   {


public   static   void   main(String[]   args)   {
            byte[]   i   =   null;
int   score   =   0;
try   {
score   =   System.in.read(i);
}   catch   (IOException   e)   {

e.printStackTrace();
}
                String   str=new   String();
str=(score> =90)? "A ":((score> =60)? "B ": "C ");
System.out.println(str);
            }
}


异常为
Exception   in   thread   "main "   java.lang.NullPointerException
at   java.io.FilterInputStream.read(Unknown   Source)
at   test.io.testaaa.main(testaaa.java:14)

这是为什么呢?
程序本身没什么错误

------解决方案--------------------
谁说程序本身没错误?
------解决方案--------------------
晕,这还没错误?


你的i数组是null,引用的时候当然要出现NullPointerException了。
------解决方案--------------------
byte[] i = null;~~~ ||**||
------解决方案--------------------
o_o
------解决方案--------------------
new 一下就ok啦~~