简体   繁体   English

是什么导致NullPointerException?

[英]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中,并且此错误使我无法查看程序的其余部分是否正常!

Heres the Source 继承人的来源

and heres the Logcat 这是Logcat

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.

相关问题 是什么导致了这个NullpointerException? - What's causing this NullpointerException? NullPointerException,是什么导致我的错误? - NullPointerException, what is causing my error? 此NullPointerException的来源是什么 - What's the source of this NullPointerException 是什么导致 Flutter 2.10 应用程序的 dispatchWindowVisibilityChanged 出现 NullPointerException? - What is causing a NullPointerException in dispatchWindowVisibilityChanged for Flutter 2.10 app? Android Studio - 我无法弄清楚是什么导致我的 StringArray 返回 NullPointerException,因为它记录为已初始化和填充 - Android Studio - I can't figure out what's causing my StringArray to return a NullPointerException because it's logging as initialized & populated java.lang.NullPointerException无法找出导致错误的原因 - java.lang.NullPointerException Cant figure out what is causing the error 在不导致 java.NullPointerException 的情况下获取 Spinner 的选定项 - Getting a Spinner's selected item without causing a java.NullPointerException MediaPlayer,onItemClickListener和NullPointerException。 怎么了? - MediaPlayer, onItemClickListener and a NullPointerException. What's wrong? 使用ExoPlayer时出现“ NullPointerException”的原因是什么? - What's the reason for 'NullPointerException' in using ExoPlayer? getWritableDatabase()导致nullPointerException - getWritableDatabase() causing nullPointerException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM