[英]What's causing the NullPointerException?
Im just coding the Android application which I thought of in order to learn the SDK a little more and ran into a problem when trying my program with the emulator. 我只是编写我想过的Android应用程序,以进一步学习SDK,并在使用模拟器尝试程序时遇到问题。 The application installs normally and then closes only to give me a logcat saying theres a NullPointerException in the main class.
该应用程序将正常安装,然后关闭,只给我一个日志,提示主类中存在NullPointerException。 I cant manage to find it anywhere and research says that theres an object being used without it being initialized?
我无法在任何地方找到它,研究表明有一个对象在使用时没有初始化? I dont think this is possible as if it were the case, Eclipse would give me an error, but in this case it is a runtime exception.
我不认为这是可能的,Eclipse会给我一个错误,但是在这种情况下,它是运行时异常。 I do not have a lot of programming experience especially in Android and this bug is stopping me from seeing if the rest of my program works!
我没有很多编程经验,尤其是在Android中,并且此错误使我无法查看程序的其余部分是否正常!
Thanks in advance for any help 预先感谢您的任何帮助
The error occurs on line 80 in your onCreate method in IOweYou.java. 该错误发生在IOweYou.java中的onCreate方法的第80行上。 You can see it on line 19 in the stacktrace you posted.
您可以在发布的堆栈跟踪中的第19行看到它。
08-03 07:11:35.068: E/AndroidRuntime(681): at com.andrei.iou.IOweYou.onCreate(IOweYou.java:80)
Is localEL properly defined? 是否正确定义了localEL?
EDIT: make your activity extend ExpandableListActivity instead of activity. 编辑:使您的活动扩展ExpandableListActivity而不是活动。 Then remove setContentView.
然后删除setContentView。 And change
并改变
localEl.setListAdapter(mAdapter);
to 至
this.setListAdapter(mAdapter);
and your list will show. 然后您的列表就会显示出来。 However clicking on the item will still make it crash but its a start!
但是,单击该项目仍会使其崩溃,但这是一个开始!
EDIT2: here is an example I found. EDIT2:这是我发现的一个示例。 http://smartandroidians.blogspot.com.es/2010/04/expandablelistactivity-in-android.html
http://smartandroidians.blogspot.com.es/2010/04/expandablelistactivity-in-android.html
I think the problem is that your ExpandableListActivity localEl
has been created but not launched. 我认为问题在于您的
ExpandableListActivity localEl
已创建但尚未启动。 When you call localEL.setListAdapter(mAdapter);
当您调用
localEL.setListAdapter(mAdapter);
it internally calls its setContentView
, as is shown in the log. 它在内部调用其
setContentView
,如日志中所示。 Probably getWindow()
returns null because the activity has not yet been initalized. 由于尚未初始化活动,因此
getWindow()
可能返回null。
Without knowing much of what you want to do, perhaps your activity should instead inherit from ExpandableListActivity? 在不了解您想做什么的情况下,也许您的活动应该继承自ExpandableListActivity?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.