没有新捆绑启动意图

时间:2011-11-28 21:35:15

标签: android class android-activity android-intent resume

我有一个列表单击方法,它启动一个新活动并给它一个包

protected void onListItemClick(ListView l , View v, int position, long id){
  super.onListItemClick(l, v, position, id);


  Intent lis = new Intent(this, MusicService.class);
  stopService(lis);  

  Object o = this.getListAdapter().getItem(position);
  String songpen = o.toString();
  String artwork = albumartwork.get(songtitle.indexOf(songpen));
  String artistpen = artistname.get(songtitle.indexOf(songpen)); 
  String albumpen = albumname.get(songtitle.indexOf(songpen));
  String pathpen = path.get(songtitle.indexOf(songpen));

  int songpos = songtitle.indexOf(o);

    Intent i  = new Intent(IplayerActivity.this, SongPlaying.class);
    i.putExtra("songnamekeyword", songpen);
    i.putExtra("artistkeyword", artistpen);
    i.putExtra("albumkeyword", albumpen);
    i.putExtra("pathkeyword", pathpen);
    i.putExtra("artworkkeyword", artwork);

    i.putExtra("position", songpos);

    i.putExtra("nextsong", songtitle);
    i.putExtra("nextartist", artistname);
    i.putExtra("nextalbum", albumname);
    i.putExtra("nextpath", path);
    i.putExtra("nextartwork", albumartwork);

    startActivity(i);

}

我想创建一个正在播放的捆绑包,该捆绑包启动Songplaying类,其中包含与已有的完全相同的信息...基本上我想恢复该类,因为它没有改变任何东西。但是当我这样做时

             Intent k = new Intent(this, SongPlaying.class);        
            startActivity(k);

我收到错误。我只想用以前的信息重新加载SongPlaying类。

11-28 15:46:50.943: ERROR/AndroidRuntime(817): FATAL EXCEPTION: main
11-28 15:46:50.943: ERROR/AndroidRuntime(817): java.lang.RuntimeException: Unable to create service unjustentertainment.com.MusicService: java.lang.NullPointerException
11-28 15:46:50.943: ERROR/AndroidRuntime(817):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2969)
11-28 15:46:50.943: ERROR/AndroidRuntime(817):     at android.app.ActivityThread.access$3300(ActivityThread.java:125)
11-28 15:46:50.943: ERROR/AndroidRuntime(817):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2087)
11-28 15:46:50.943: ERROR/AndroidRuntime(817):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 15:46:50.943: ERROR/AndroidRuntime(817):     at android.os.Looper.loop(Looper.java:123)
11-28 15:46:50.943: ERROR/AndroidRuntime(817):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-28 15:46:50.943: ERROR/AndroidRuntime(817):     at java.lang.reflect.Method.invokeNative(Native Method)
11-28 15:46:50.943: ERROR/AndroidRuntime(817):     at java.lang.reflect.Method.invoke(Method.java:521)
11-28 15:46:50.943: ERROR/AndroidRuntime(817):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-28 15:46:50.943: ERROR/AndroidRuntime(817):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-28 15:46:50.943: ERROR/AndroidRuntime(817):     at dalvik.system.NativeStart.main(Native Method)
11-28 15:46:50.943: ERROR/AndroidRuntime(817): Caused by: java.lang.NullPointerException
11-28 15:46:50.943: ERROR/AndroidRuntime(817):     at unjustentertainment.com.MusicService.onCreate(MusicService.java:36)
11-28 15:46:50.943: ERROR/AndroidRuntime(817):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2959)

我的音乐服务类需要一条播放媒体播放器的路径。但是这个新的意图我没有添加任何额外的东西,因为我只想显示完全像我点击正在播放按钮之前的SongPlaying类

1 个答案:

答案 0 :(得分:0)

你可能没有在IplayerActivity.this

中检查你的onCreate方法中的包是否有.extra。

否则,您需要包含更多信息,因为很难分辨您的NPE来自何处。