Transition of activities with serializable classes (getIntent problem)

Asked

Viewed 63 times

-1

I have a problem while passing a serializable class. I insert it into the Bundle as follows.

public void voltarMain(View view) {
    Intent myIntent = new Intent(getApplicationContext(), MainActivity.class);

    myIntent.putExtra("Cliente", cliente);

    startActivity(myIntent);
    finish();
}

When I try to receive it in the second Activity it is in the Bundle but gives me an error of "java.lang.Nullpointerexception: Attempt to invoke virtual method 'int java.math.Roundingmode.ordinal()' on a null Object Reference"

inserir a descrição da imagem aqui

This is how I try to get it.

inserir a descrição da imagem aqui

This is the error obtained

inserir a descrição da imagem aqui

Note: On a tablet Huawei Mediapad T5 (android 8.0) works correctly while this error comes to me in Samsung A7 2018 (android 9.0)

1 answer

0

Instead of creating a Bundle and putting in your Input, place your client object with the putExtra function of the Intent class:

Intent intent = (...)
i.putExtra("Cliente", cliente);

P.S.: use the stack overflow code block itself, which will adapt to the screen size, and allows people to copy the text easily.

  • Thanks for the tip of the code block. As for the solution presented I have also tried and with the same result :(

  • Have you ever tried to put a breakpoint on startActivity to see if Intent has the extra you put in? It’s weird that it didn’t work because I always use it this way and I’ve never had a problem.

  • The strange thing is that on an android tablet 8 works perfectly and on an android phone 9 no longer da

Browser other questions tagged

You are not signed in. Login or sign up in order to post.