The question is published on by Tutorial Guruji team.
I have this Activity (the MainActivity
, from package package com.example.myapplication
) that receives an Intent
of class “BeanValidacion
“.
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Bundle willirex = getIntent().getExtras(); if(willirex!=null) { BeanValidacion datos = (BeanValidacion) willirex.get("paramIn"); Toast.makeText(MainActivity.this,datos.getIdNumber(),Toast.LENGTH_LONG).show(); }
And I want to call it with a different APK (package com.adon.intents
) and send an Intent
, as I do with String Intent
s, but this time, I want to send an object of class “BeanValidacion
“:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); BeanValidacion datos = new BeanValidacion(); datos.setIdNumber("12345"); Intent next = new Intent(); next.setClassName("com.example.myapplication", "com.example.myapplication.MainActivity"); next.putExtra("paramIn", datos); startActivity(next); }
When I execute the com.adon.intents
APK to send the intent, I got this error on com.example.myapplication
:
ClassNotFoundException reading a Serializable object (name = com.adon.intents.BeanValidacion
In this line:
Toast.makeText(MainActivity.this,datos.getIdNumber(),Toast.LENGTH_LONG).show();
This doesn’t happen when sending just a String
, but I am having problems solving this one.
Regards
Answer
You should put the BeanValidacion.java
file in the exact package hierarchy com.adon.intents.BeanValidacion
on the second app. Also, both classes should have the same serialVersionUID
.