0

I'm having a problem with Android when passing a 2d array to another activity. I have no problems sending it through a extra as a serializable. But when receiving it, i get the following error:

E/AndroidRuntime(7396): Caused by: java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[][]

I'm using the following code:

public void getMatriz(){
    Bundle extras = getIntent().getExtras(); 
    if(extras!=null){
        String[][] matriz = (String[][]) extras.getSerializable("matriz");

    }

}

Can someone help me solve this problem? Thanks in advance.

1 Answers1

0

You need to deserialize to get back stream array.

For e.g. following code snippet you can pass serializable as ObjectInputStream.

ObjectInputStream ois = new ObjectInputStream(is);
return (String[][]) ois.readObject();
Ry-
  • 218,210
  • 55
  • 464
  • 476
Sachin Thapa
  • 3,559
  • 4
  • 24
  • 42