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 trialAdesh Thakare
685 PointsI think I am having a problem with the Log.d(TAG,name) When I run the project it says "Unfortunately Stopped"
Intent intent = getIntent();
String name = intent.getStringExtra("name");
Log.d(TAG,name);
christopher irwin
1,540 PointsI had the same problem it looks like the video jumps or skips on a link of code that I did not see get typed in. Double check the last three lines.
2 Answers
Steve Hunter
57,712 PointsHi there,
Your code looks fine as long as two things have been added - these are in the video.
You start in the MainActivity
where you add a string value to the intent using putExtra
and the key called name
. You're then using the key to get the data out of the intent in StoryActivity
. So, you need to have used the key "name"
for this to work - the key must be identical in both activities.
Second, you need to have added the constant called TAG
to the top of your class. That way the Log.d
knows what TAG
is. This line is added at 2:07 in the video.
I hope that helps. If not, in the Android Log, where you're expecting your message to appear, you should get an error message which explains why your app "unfortunately stopped". Post those error messages in here. They'll tell us why your app crashed.
Steve.
Marc Reid
7,830 PointsNewer versions of Android Studio seem to prefer you to use...
import static android.util.Log.d;
and then
d(TAG, name);
for some reason following the video exactly produces an error.
Suleyman Orazgulyyev
Courses Plus Student 5,798 PointsSuleyman Orazgulyyev
Courses Plus Student 5,798 PointsIt seems good, are you sure that the String that you are providing to the
getStringExtra
was used as the key in the activity that the intent was sent from? I mean did you do that when you were sending the intent:intent.putExtra("name", yourstring)
Because the String (which acts as a key) that you provide in putExtra has to be the same in getStringExtra.