這裏是得到NullPointerException異常錯誤代碼:的InputStream返回NullPointerException異常(JAVA)
InputStream is = getAssets().open("twentyone.txt");
InputStreamReader iz=new InputStreamReader(is);
BufferedReader br = new BufferedReader(iz);
可能是什麼回事?
*編輯:的printStackTrace
03-19 18:20:18.662: E/AndroidRuntime(929): Caused by: java.lang.NullPointerException
編輯2:代碼直到異常:
public class ListViewAa3 extends ListViewA{
public String[] process(String cti)throws IOException{
String ctid=cti;
Log.d("Outside try invoked","tag1");
try{
Log.d("beginning of try invoked","tag2");
try{
InputStream is = getAssets().open("USCOUNTIES.txt");
InputStreamReader iz=new InputStreamReader(is);
BufferedReader br = new BufferedReader(iz);}catch(Exception e){e.printStackTrace();}
'getAssets()'可能爲空 – 2013-03-19 18:16:13
如何解決?我的資產文件夾中有上述文件.. – 2013-03-19 18:16:51
很難說沒有看到更多的代碼,但首先通過使用調試器或查看堆棧跟蹤來確定'getAssets()'是否爲空。然後找出它爲什麼是空的。 – 2013-03-19 18:19:40