I'm trying to pass my player data into another activity which has been parsed from an xml file (PlayerFromXML). However, when I run MainActivity, it boots up just fine, but when I click a player, my app crashes and returns this error - android.os.BadParcelableException: Parcelable encountered IOException writing serializable object (name = com.example.x.PlayersFromXML)

package com.example.x;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;

import java.io.Serializable;

public class MainActivity extends AppCompatActivity implements RecyclerViewInterface{

    private RecyclerView recyclerView = null;
    private DataAdapter adapter = null;

    public PlayersFromXML players = null;

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

        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setItemAnimator(new DefaultItemAnimator());

        players = new PlayersFromXML(this);

//        String [] images = players.getImages();
        String [] names = players.getNames();
        String [] positions = players.getPositions();

        adapter = new DataAdapter(this, R.layout.players_list, names, positions, this);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onItemClick(int position) {
        Intent intent = new Intent(MainActivity.this, DetailsActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("data", players);
        intent.putExtras(bundle);
        startActivity(intent);
    }
}









E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.example.assignment_1, PID: 11354
        android.os.BadParcelableException: Parcelable encountered IOException writing serializable object (name = com.example.assignment_1.PlayersFromXML)
            at android.os.Parcel.writeSerializable(Parcel.java:2751)
            at android.os.Parcel.writeValue(Parcel.java:2517)
            at android.os.Parcel.writeValue(Parcel.java:2316)
            at android.os.Parcel.writeArrayMapInternal(Parcel.java:1265)
            at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1799)
            at android.os.Bundle.writeToParcel(Bundle.java:1362)
            at android.os.Parcel.writeBundle(Parcel.java:1334)
            at android.content.Intent.writeToParcel(Intent.java:11538)
            at android.os.Parcel.writeTypedObject(Parcel.java:2157)
            at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:2034)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1801)
            at android.app.Activity.startActivityForResult(Activity.java:5470)
            at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:712)
            at android.app.Activity.startActivityForResult(Activity.java:5428)
            at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:693)
            at android.app.Activity.startActivity(Activity.java:5926)
            at android.app.Activity.startActivity(Activity.java:5893)
            at com.example.assignment_1.MainActivity.onItemClick(MainActivity.java:53)
            at com.example.assignment_1.DataAdapter$ViewHolder$1.onClick(DataAdapter.java:67)
            at android.view.View.performClick(View.java:7506)
            at android.view.View.performClickInternal(View.java:7483)
            at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
            at android.view.View$PerformClick.run(View.java:29335)
            at android.os.Handler.handleCallback(Handler.java:942)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loopOnce(Looper.java:201)
            at android.os.Looper.loop(Looper.java:288)
            at android.app.ActivityThread.main(ActivityThread.java:7898)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
         Caused by: java.io.NotSerializableException: com.example.assignment_1.MainActivity
            at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1240)
            at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1604)
            at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1565)
            at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1488)
            at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234)
            at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:354)
            at android.os.Parcel.writeSerializable(Parcel.java:2746)
            at android.os.Parcel.writeValue(Parcel.java:2517) 
            at android.os.Parcel.writeValue(Parcel.java:2316) 
            at android.os.Parcel.writeArrayMapInternal(Parcel.java:1265) 
            at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1799) 
            at android.os.Bundle.writeToParcel(Bundle.java:1362) 
            at android.os.Parcel.writeBundle(Parcel.java:1334) 
            at android.content.Intent.writeToParcel(Intent.java:11538) 
            at android.os.Parcel.writeTypedObject(Parcel.java:2157) 
            at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:2034) 
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1801) 
            at android.app.Activity.startActivityForResult(Activity.java:5470) 
            at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:712) 
            at android.app.Activity.startActivityForResult(Activity.java:5428) 
            at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:693) 
            at android.app.Activity.startActivity(Activity.java:5926) 
            at android.app.Activity.startActivity(Activity.java:5893) 
            at com.example.assignment_1.MainActivity.onItemClick(MainActivity.java:53) 
            at com.example.assignment_1.DataAdapter$ViewHolder$1.onClick(DataAdapter.java:67) 
            at android.view.View.performClick(View.java:7506) 
            at android.view.View.performClickInternal(View.java:7483) 
            at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0) 
            at android.view.View$PerformClick.run(View.java:29335) 
            at android.os.Handler.handleCallback(Handler.java:942) 
            at android.os.Handler.dispatchMessage(Handler.java:99) 
            at android.os.Looper.loopOnce(Looper.java:201) 
            at android.os.Looper.loop(Looper.java:288) 
            at android.app.ActivityThread.main(ActivityThread.java:7898) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 
0

There are 0 answers