0
我想這個代碼在mainactivity未能從ListActivity交付結果ResultInfo到MainActivity
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
//getting listitem index
int songIndex = position;
// Starting new intent
Intent in = new Intent(getApplicationContext(), MainActivity.class);
//sending songIndex to playactivity
in.putExtra("songIndex", songIndex);
setResult(100, in);
//closing PlayListView
finish();
,我設法得到如下結果
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == 100){
currentSongIndex = data.getExtras().getInt("songIndex");
//play selected song
playSong(currentSongIndex);
}
}
,但我得到一個RuntimeException:不提供結果ResultInfo當我點擊我的列表視圖
這裏是我的logcat
01-14 21:13:09.360: I/dalvikvm-heap(14399): Grow heap (frag case) to 4.254MB for 1127536-byte allocation
01-14 21:13:11.642: I/Choreographer(14399): Skipped 45 frames! The application may be doing too much work on its main thread.
01-14 21:13:14.440: I/Choreographer(14399): Skipped 63 frames! The application may be doing too much work on its main thread.
01-14 21:13:15.946: I/Choreographer(14399): Skipped 58 frames! The application may be doing too much work on its main thread.
01-14 21:13:17.350: W/dalvikvm(14399): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
01-14 21:13:17.550: E/AndroidRuntime(14399): FATAL EXCEPTION: main
01-14 21:13:17.550: E/AndroidRuntime(14399): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=100, data=Intent { cmp=com.example.mediaplayer/.MainActivity (has extras) }} to activity {com.example.mediaplayer/com.example.mediaplayer.MainActivity}: java.lang.NullPointerException
01-14 21:13:17.550: E/AndroidRuntime(14399): at android.app.ActivityThread.deliverResults(ActivityThread.java:3319)
01-14 21:13:17.550: E/AndroidRuntime(14399): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3362)
01-14 21:13:17.550: E/AndroidRuntime(14399): at android.app.ActivityThread.access$1100(ActivityThread.java:141)
01-14 21:13:17.550: E/AndroidRuntime(14399): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
01-14 21:13:17.550: E/AndroidRuntime(14399): at android.os.Handler.dispatchMessage(Handler.java:99)
01-14 21:13:17.550: E/AndroidRuntime(14399): at android.os.Looper.loop(Looper.java:137)
01-14 21:13:17.550: E/AndroidRuntime(14399): at android.app.ActivityThread.main(ActivityThread.java:5041)
01-14 21:13:17.550: E/AndroidRuntime(14399): at java.lang.reflect.Method.invokeNative(Native Method)
01-14 21:13:17.550: E/AndroidRuntime(14399): at java.lang.reflect.Method.invoke(Method.java:511)
01-14 21:13:17.550: E/AndroidRuntime(14399): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-14 21:13:17.550: E/AndroidRuntime(14399): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-14 21:13:17.550: E/AndroidRuntime(14399): at dalvik.system.NativeStart.main(Native Method)
01-14 21:13:17.550: E/AndroidRuntime(14399): Caused by: java.lang.NullPointerException
01-14 21:13:17.550: E/AndroidRuntime(14399): at com.example.mediaplayer.MainActivity.playSong(MainActivity.java:208)
01-14 21:13:17.550: E/AndroidRuntime(14399): at com.example.mediaplayer.MainActivity.onActivityResult(MainActivity.java:195)
01-14 21:13:17.550: E/AndroidRuntime(14399): at android.app.Activity.dispatchActivityResult(Activity.java:5293)
01-14 21:13:17.550: E/AndroidRuntime(14399): at android.app.ActivityThread.deliverResults(ActivityThread.java:3315)
01-14 21:13:17.550: E/AndroidRuntime(14399): ... 11 more
任何幫助將很多提前
你也可以用你的playSong方法,這似乎是造成問題的原因 –