0

Im tryin to bundle an Array of Arrays but is not working. Heres a snipped of code for better understanding:

Declaring and Initializing the variable

Inversor[][] reg_equipment= new Inversor[7][5];
for(int i=0; i<7; i++)
{
  for(int j=0;j<5;j++)
  {
    reg_equipment[i][j]= new Inversor();
  }
}
//....

Putting the variable in the bundle

bundle.putSerializable("reg_equipment", reg_equipment);

Intent myIntent =new  Intent(RegisterEquipmentInversor.this,RegisterEquipmentMain.class);
                myIntent.putExtras(bundle);

                startActivity(myIntent);

At this point, the reg_equipment is filled with Inversors [Inversor[0],Inversor[1]....,Inversor[6]] and inside those There are more Inversors.

But when I go "get" the bundle in the other class

reg_equipment = (Inversor[][]) extras.getSerializable("reg_equipment");

This is whats inside de reg_equipment - [Object[0],Object[1],...,[Object[6]] and inside those Objects there are Inversors. Why does this happens ? How can I fix it ?

The class Inversor implements Serializable

Thanks

2 Answers 2

3

You should try to create a Serializable class that has only one property, which should be your array of Inversor arrays and put that object in your intent. something like

public class InversorArrays implements Serializable {
    public final static int serialVersionUID = //let eclipse generate your uid
    public Inversor[][] myArray = null;
    public InversorArrays (Inversor[][] _myArray){
        this.myArray = _myArray;
    }
}

and then, in your activity, create an instance of InversorArrays an pass it to the intent

Of course, Inversor and its properties should be serializable too.

This workaround sometimes saved me a lot of time and problems with typecasting and conversion problems

Sign up to request clarification or add additional context in comments.

4 Comments

Sounds like a good idea. I'll try and let you know the answer!
Why do I need the serialVersionUID ?
it should be automatically added by eclipse when you're declarating a class that implements serializable.
It worked! Thanks a lot ;) Still its a mystery why can u bundle a simple array but cant bundle properly an array of arrays..
0

I am not sure, but have you made the investor class serializable? I think if we could get a basic view of the investor class, that may lead to some light.

I would say start off by making Investor serializable. http://www.tutorialspoint.com/java/java_serialization.htm

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.