在没有新捆绑包的情况下启动意图

发布于 2024-12-18 14:08:12 字数 3373 浏览 1 评论 0原文

我有一个列表单击方法,它启动一个新活动并为其提供一个捆绑包

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);

}

我想创建一个正在播放的捆绑包,它使用与已有的信息完全相同的信息启动歌曲播放类...基本上我只想继续上课,不做任何改变。但是当我这样做时

             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 类,就像我单击“正在播放”按钮之前一样

I have a which is a list click method that starts a new activity and gives it a bundle

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);

}

I want to create a Now Playing bundle which starts the Songplaying class with the exact same information as it already had... Basically i want to just resume the class as it was without changing anything. But when i do this

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

I get an error. I just want to reload the SongPlaying class with information it already had previously.

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)

My music service class needs a path to play the media player. but with this new intent im not adding any extras because i simply want to display SongPlaying class exactly as it was before i clicked the Now Playing Button

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瀞厅☆埖开 2024-12-25 14:08:12

您可能没有检查 IplayerActivity.this 中 onCreate 方法内的捆绑包是否有 Extra,

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

You're probably not checking if the bundle hasExtra inside your onCreate method in IplayerActivity.this

Otherwise, you need to include more information because it's difficult to tell where your NPE is coming from.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文