E / AndroidRuntime:致命异常:主要。 ExpadableListView Isses

时间:2017-03-18 12:23:06

标签: java android xml

当我尝试运行我的应用程序时,我得到以下错误,我只有在实现和expandablelistview后出现这些错误:

7686 / com.example.admin.n0499049 E / AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.admin.n0499049, PID: 7686
java.lang.RuntimeException: Unable to start activity ComponentInfo { com.example.admin.n0499049 / com.example.admin.n0499049.MainActivity }: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ExpandableListView.setAdapter(android.widget.ExpandableListAdapter)'
on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2726)
at android.app.ActivityThread. - wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1477)
at android.os.Handler.dispatchMessage(Handler.java: 102)
at android.os.Looper.loop(Looper.java: 154)
at android.app.ActivityThread.main(ActivityThread.java: 6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ExpandableListView.setAdapter(android.widget.ExpandableListAdapter)'
on a null object reference
at com.example.admin.n0499049.MainActivity.onCreate(MainActivity.java: 34)
at android.app.Activity.performCreate(Activity.java: 6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: 1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2726) 
at android.app.ActivityThread. - wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1477) 
at android.os.Handler.dispatchMessage(Handler.java: 102) 
at android.os.Looper.loop(Looper.java: 154) 
at android.app.ActivityThread.main(ActivityThread.java: 6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 776) 

1 个答案:

答案 0 :(得分:0)

您的ExpandableListView为空,请务必正确启动。在你致电ExpandableListView.setAdapter(...)

之前