Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

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