Android Build an Interactive Story App Intents and Multiple Activities Investigating a NullPointerException

Sean Walker
Sean Walker
1,792 Points

my app doesn't have any errors!!!!

hey everyone! Ben Jakuben said that there must be an error if we don't add an if statement and null pointer code and stuff like that... but i haven't import any of them and my app works without any errors just fine...is that because the updated version of android studio or something ?! cause i've also skipped some lines and it works fineeee!!! omg what should i do?! here's my code:

    Intent intent = getIntent();
    intent.getStringExtra("name");

Ben said it must be something like :

    Intent intent = getIntent();
    String name = intent.getStringExtra("name");

when i write my code like how Ben said it must be it keeps telling me that the variable name was never used and shows it in grey color...pressing alt+enter doesn't do much either it just removes Ben's said part and changes it like the one i've wrote! omg...heeeeelp!

2 Answers

Yusuf Mohamed
Yusuf Mohamed
2,627 Points

The problem is you haven't done anything wrong. In the video if you watch the problem is that Ben has 2 keys with identical names. So he was trying to simulate a problem that could happen in real life when you code that you accidentally use for example an upper case lettter at the key in which this case was name.

Intent intent = getIntent();
    String name = intent.getStringExtra("name");

That's your code

Intent intent = getIntent();
    String name = intent.getStringExtra("Name");

That's his code. You see the difference?

Sean Walker
Sean Walker
1,792 Points

thanks,but the problem is that neither upper case name or lower case name both are showed in grey and says the variable has never been used before...

Seckin Arslan
Seckin Arslan
686 Points

my app doesn't have any errors and i did use the same variable name