尝试通过 bundle 传递 arraylist 时出现错误

I am getting error while trying to pass an arraylist through bundle

我在尝试通过 bundle 传递数组列表时遇到错误,请帮忙

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sandyzfeaklab.Breakdown_app/com.sandyzfeaklab.breakdown_app.Data_input}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.Serializable android.os.Bundle.getSerializable(java.lang.String)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.Serializable android.os.Bundle.getSerializable(java.lang.String)' on a null object reference at com.sandyzfeaklab.breakdown_app.Data_input.onCreate(Data_input.java:61)

下面是我收到的包裹 activity

public class Data_input extends AppCompatActivity {

    String Part = "Part Name", problem_desc = "Problem", action_taken = "Action Taken", spares_used = "Spares Used", sap_no = "Sap No", operation = "Operation", end_time = "End Time", Action_taken_by = "Action taken by ", start_time = "Start Time";

    TextView starttime, endtime, time_taken;

    ArrayList<Sap_code_Model> models = new ArrayList<>();

    private static final int SECOND_ACTIVITY_REQUEST_CODE = 0;



    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_data_input);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FirebaseFirestore db = FirebaseFirestore.getInstance();

        EditText part_name, problem_desc_et, action_taken_et, spares_used_et, sap_no_et;

        Bundle bundle= getIntent().getExtras();
        models= (ArrayList<Sap_code_Model>) bundle.getSerializable("Codes");

        Toast.makeText(this, models.size(), Toast.LENGTH_SHORT).show(); 

这是我的模特class

public class Sap_code_Model implements Serializable {

private long sap_code;
private String sap_description;
private int sap_qty;

public Sap_code_Model() {
}



public long getSap_code() {
    return sap_code;
}

public Sap_code_Model setSap_code(long sap_code) {
    this.sap_code = sap_code;
    return this;
}

public String getSap_description() {
    return sap_description;
}

public Sap_code_Model setSap_description(String sap_description) {
    this.sap_description = sap_description;
    return this;
}

public int getSap_qty() {
    return sap_qty;
}

public Sap_code_Model setSap_qty(int sap_qty) {
    this.sap_qty = sap_qty;
    return this;
}

}

数据发送Activity这里我正在尝试发送arraylist

mDataBinding.fabSave.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Add_Sap_codes.this, Data_input.class);
                    Bundle bundle= new Bundle();
                    bundle.putSerializable("Codes",data);
                    intent.putExtras(bundle);
                    setResult(RESULT_OK, intent);
                    startActivity(intent);
                }
            });

我发现了我的问题,

下面我指的是我的模型在没有验证天气是否为空的情况下丢失了,所以我添加了 if 语句来检查数据是否不为空然后它起作用了

Bundle bundle=getIntent().getExtras(); models= (ArrayList) bundle.getSerializable("代码");