0

我正在尝试传递一些自定义对象(Parcelable),这是传递活动代码

Intent resultsActivity = new Intent(GamePlayActivity.this, Results.class);
                Bundle extras = new Bundle();
                resultsActivity.putExtra("length", arrayOfDrills.length);
                for(int i = 0; i < arrayOfDrills.length; i++ ){
                    extras.putParcelable("drill_" + i, arrayOfDrills[i]);
                }
                resultsActivity.putExtras(extras);
                startActivity(resultsActivity);

这是接收活动代码:

public class Results extends Activity {
    Drill[] arrayOfDrills;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_results);

        Bundle extras  = getIntent().getExtras();
        //int length = extras.getInt("length"); 
        int length = 3;
        Log.w("length", ""+length);
        arrayOfDrills = new Drill[length];
        for(int i = 0; i < length; i++ ){
            arrayOfDrills[i] = extras.getParcelable("drill_" + i);
        } 

我在 logCat 中有这个:

12-28 22:10:07.944: E/AndroidRuntime(855): Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@40512e58: Unmarshalling unknown type code 7077993 at offset 148
12-28 22:10:07.944: E/AndroidRuntime(855):  at android.os.Parcel.readValue(Parcel.java:1913)
12-28 22:10:07.944: E/AndroidRuntime(855):  at android.os.Parcel.readMapInternal(Parcel.java:2082)
12-28 22:10:07.944: E/AndroidRuntime(855):  at android.os.Bundle.unparcel(Bundle.java:208)
12-28 22:10:07.944: E/AndroidRuntime(855):  at android.os.Bundle.getParcelable(Bundle.java:1100)
12-28 22:10:07.944: E/AndroidRuntime(855):  at com.simplemathgame.Results.onCreate(Results.java:25)
12-28 22:10:07.944: E/AndroidRuntime(855):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-28 22:10:07.944: E/AndroidRuntime(855):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

为什么会发生崩溃???

4

0 回答 0