首页 问答 问答详情
1193502575928815616 1188088367049461760 喜马拉雅项目开发(空指针异常)
0

和视频中写的一模一样,但是总报空指针异常是怎么回事?

2019-11-10 20:11:16.327 4931-4931/com.example.himalaya E/AndroidRuntime: FATAL EXCEPTION: main

  Process: com.example.himalaya, PID: 4931

  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.himalaya/com.example.himalaya.PlayerActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object[] java.util.Collection.toArray()' on a null object reference

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

    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)

    at android.app.ActivityThread.-wrap12(ActivityThread.java)

    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)

    at android.os.Handler.dispatchMessage(Handler.java:102)

    at android.os.Looper.loop(Looper.java:154)

    at android.app.ActivityThread.main(ActivityThread.java:6077)

    at java.lang.reflect.Method.invoke(Native Method)

    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)

    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

   Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object[] java.util.Collection.toArray()' on a null object reference

    at java.util.ArrayList.addAll(ArrayList.java:562)

    at com.example.himalaya.adapters.PlayTrackPagerAdapter.setData(PlayTrackPagerAdapter.java:54)

    at com.example.himalaya.PlayerActivity.onListLoaded(PlayerActivity.java:369)

    at com.example.himalaya.presenters.PlayerPresenter.getPlayList(PlayerPresenter.java:181)

    at com.example.himalaya.PlayerActivity.onCreate(PlayerActivity.java:89)

    at android.app.Activity.performCreate(Activity.java:6662)

    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)

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

    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 

    at android.app.ActivityThread.-wrap12(ActivityThread.java) 

    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 

    at android.os.Handler.dispatchMessage(Handler.java:102) 

    at android.os.Looper.loop(Looper.java:154) 

    at android.app.ActivityThread.main(ActivityThread.java:6077) 

    at java.lang.reflect.Method.invoke(Native Method) 

    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 

    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 


1 个回答
提交答案
  • 0

    空指针是最好解决的呀,把这个地方的代码贴出来呗。PlayTrackPagerAdapter.java 第54行前后大部分。

    1153952789488054272  评论   $赏    
    举报
    拉大锯
  • 最佳答案
     评论   $赏  
    举报
    •  回复 @:
      {{sub.publishtime|formatDate}}   回复
相关问题