错误如下:

09-30 13:40:05.042 4628-4628/com.lyf.ai.demo E/AndroidRuntime: FATAL EXCEPTION: main

Process: com.lyf.ai.demo, PID: 4628

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lyf.ai.demo/com.lyf.ai.demo.MainActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lyf.ai.demo/com.lyf.ai.demo.ActivityOne}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' 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.RuntimeException: Unable to start activity ComponentInfo{com.lyf.ai.demo/com.lyf.ai.demo.ActivityOne}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)

at android.app.ActivityThread.startActivityNow(ActivityThread.java:2465)

at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:136)

at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:348)

at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:724)

at android.widget.TabHost.setCurrentTab(TabHost.java:388)

at android.widget.TabHost.addTab(TabHost.java:222)

at com.lyf.ai.demo.MainActivity.initView(MainActivity.java:47)

at com.lyf.ai.demo.MainActivity.onCreate(MainActivity.java:25)

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)

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference

at com.lyf.ai.demo.ActivityOne.onCreate(ActivityOne.java:43)

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.startActivityNow(ActivityThread.java:2465)

at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:136)

at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:348)

at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:724)

at android.widget.TabHost.setCurrentTab(TabHost.java:388)

at android.widget.TabHost.addTab(TabHost.java:222)

at com.lyf.ai.demo.MainActivity.initView(MainActivity.java:47)

at com.lyf.ai.demo.MainActivity.onCreate(MainActivity.java:25)

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)

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐