1

Hello everyone, I need to take parameter id = 55 from this picture, does anyone know how to do that? Thanks!!

System.out.println(voznja.toString());

enter image description here

When I try to log in console, I always get the error that object reference is null.

3
  • Could you post code snippet and logcat in here? Feb 1, 2021 at 11:37
  • @Daniel.Wang yes i can Feb 1, 2021 at 11:42
  • okay, Please update your question. Feb 1, 2021 at 11:47

3 Answers 3

1

When you call extras.getString("voznja") it returns null because voznja is not a String. Its class is Voznja so you have to write your code like this:

Voznja voznja = (Voznja) extras.getSerializableExtra("voznja");

Now you can get the id by this line:

voznja.get("id");
2
0

I think that the id you are trying to read is in an object. I would first suggest using : voznja = extras.getSerializableExtra("voznja")
Then, I would use this to extract the id from the object :
voznja.get(0);
let me know if that helps

3
0

If your class implements Parcelable use:

Voznja voznja = extras.getParcelableExtra("voznja");

And if it implements Serializable use:

Voznja voznja = extras.getSerializableExtra("voznja");

And then you could get the id from your object.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.