阵列NullPointerException异常? [英] Array NullPointerException?
本文介绍了阵列NullPointerException异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
确定。我不明白为什么我的code是报告NullPointerException异常,但我一直在这里相当试图弄清楚一段时间。
和没有,文件
不是空
。
的编辑:这是我犯的一个错误,它为空(我没有看到订单我运行的功能的
下面是我的code:
公共字符串[]的文件;私人无效updateRefs(字符串文件路径){
尝试{
SCR ++;
文件[SCR] =文件路径; //空指针异常???
}赶上(例外五){
e.printStackTrace();
}
}
解决方案
您有新的,否则是无效:
的String []文件=新的String [10]; //或任何大小你需要
Ok. I don't get why my code is reporting a NullPointerException, but I've been here for quite a while trying to figure it out.
And no, files
is not null
.
Edit: That was a mistake on my part, it was null (I didn't see the order I was running the functions.
Here is my code:
public String[] files;
private void updateRefs(String filepath) {
try {
scr++;
files[scr] = filepath; //NullPointerException???
} catch ( Exception e ) {
e.printStackTrace();
}
}
解决方案
You have to new it, otherwise it is null:
String[] files = new String[10]; //or whatever size you need
这篇关于阵列NullPointerException异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文