简体   繁体   中英

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. The application installs normally and then closes only to give me a logcat saying theres a NullPointerException in the main class. 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. 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!

Heres the Source

and heres the Logcat

Thanks in advance for any help

The error occurs on line 80 in your onCreate method in IOweYou.java. You can see it on line 19 in the stacktrace you posted.

08-03 07:11:35.068: E/AndroidRuntime(681):      at com.andrei.iou.IOweYou.onCreate(IOweYou.java:80)

Is localEL properly defined?

EDIT: make your activity extend ExpandableListActivity instead of activity. Then remove 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. 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. When you call localEL.setListAdapter(mAdapter); it internally calls its setContentView , as is shown in the log. Probably getWindow() returns null because the activity has not yet been initalized.

Without knowing much of what you want to do, perhaps your activity should instead inherit from ExpandableListActivity?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM