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 trialEphraim Smith
11,930 PointsLogcat Debugging not working
When attempting to debug via [Log.d(TAG, variable);], the following 2 lines appear first in my Logcat:
"Not late-enabling -Xcheck:jni (already on)" "Unexpected CPU variant for X86 using defaults: x86"
And of course I don't see the Log.d output in the Logcat.
Thanks for your help guys.
Ephraim Smith
11,930 PointsHey Lauren,
So, I got the debugger to work. Now, I can't get the app to return user's name at placeholder. Program always returns "friend."
Intent intent = getIntent();
name = intent.getStringExtra("name"); // *** START ADVENTURE DOESN'T INSERT USER'S NAME ***
if(name == null || name.isEmpty()) {
name = "Friend";
}
Log.d(TAG, name); // <-- TEST DRIVEN DEVELOPMENT:)
story = new Story();
loadPage(0);
Debugger shows [D/StoryActivity: Friend]
Here's what the other end looks like...
startButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = nameField.getText().toString();
startStory(name);
}
});
}
private void startStory(String name) {
Intent intent = new Intent(this, StoryActivity.class); // <-- [INTENT OBJECT]this is how an action sends user to another activity
Resources resources = getResources();
String key = resources.getString(R.string.key_name);
intent.putExtra(key, name); // <-- [EXTRAS: "intent" data] used to pass variable(s)/data to next activity via KEY VALUE PAIR
startActivity(intent);
}
Thanks for replying!
Lauren Moineau
9,483 PointsHi Ephraim. Glad to hear you solved your previous issue. Your code looks fine to me. I even copy pasted it and it works my side: every time I enter a name in the edit text, it logs it in the Logcat.
Maybe you want to double check your key_name
string in your strings.xml resource file. Just make sure its value is name
. Since you're referring to that key as "name"
and are not using the string from the resource file in StoryActivity
, if they don't have the same value, that could be the reason you always get Friend
as you wouldn't be getting the value from the intent (name
would be null because you'd be using 2 different keys).
2 Answers
Ephraim Smith
11,930 PointsYou're awesome. That's exactly what it was. Have a good rest of your day. Thanks!
Lauren Moineau
9,483 PointsYou're welcome :) I'm glad it's fixed. Thank you. Have a great end of day too
Derek Lam
1,012 Pointshi, i've followed your instruction. However it doesn't show debug with my name in the logcat.
my logcat shows the following: 2021-04-24 11:54:05.817 8565-8580/com.example.interactivestory I/OpenGLRenderer: Initialized EGL, version 1.4 2021-04-24 11:54:05.817 8565-8580/com.example.interactivestory D/OpenGLRenderer: Swap behavior 1 2021-04-24 11:54:05.818 8565-8580/com.example.interactivestory W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 2021-04-24 11:54:05.818 8565-8580/com.example.interactivestory D/OpenGLRenderer: Swap behavior 0 2021-04-24 11:54:05.826 8565-8580/com.example.interactivestory D/EGL_emulation: eglCreateContext: 0xaa1850c0: maj 2 min 0 rcv 2 2021-04-24 11:54:05.837 8565-8580/com.example.interactivestory D/EGL_emulation: eglMakeCurrent: 0xaa1850c0: ver 2 0 (tinfo 0xaa183630) 2021-04-24 11:54:05.895 8565-8580/com.example.interactivestory D/EGL_emulation: eglMakeCurrent: 0xaa1850c0: ver 2 0 (tinfo 0xaa183630) 2021-04-24 11:54:13.523 8565-8565/com.example.interactivestory D/StoryActivity: Der 2021-04-24 11:54:13.587 8565-8580/com.example.interactivestory D/EGL_emulation: eglMakeCurrent: 0xaa1850c0: ver 2 0 (tinfo 0xaa183630) 2021-04-24 11:54:13.615 8565-8580/com.example.interactivestory D/EGL_emulation: eglMakeCurrent: 0xaa1850c0: ver 2 0 (tinfo 0xaa183630) 2021-04-24 11:54:13.653 8565-8580/com.example.interactivestory D/EGL_emulation: eglMakeCurrent: 0xaa1850c0: ver 2 0 (tinfo 0xaa183630) 2021-04-24 11:54:13.679 8565-8580/com.example.interactivestory D/EGL_emulation: eglMakeCurrent: 0xaa1850c0: ver 2 0 (tinfo 0xaa183630) 2021-04-24 11:54:13.690 8565-8565/com.example.interactivestory W/IInputConnectionWrapper: finishComposingText on inactive InputConnection 2021-04-24 11:54:13.703 8565-8580/com.example.interactivestory D/EGL_emulation: eglMakeCurrent: 0xaa1850c0: ver 2 0 (tinfo 0xaa183630) 2021-04-24 11:54:13.709 8565-8580/com.example.interactivestory D/OpenGLRenderer: endAllActiveAnimators on 0x9acefc80 (RippleDrawable) with handle 0x8ecff330
Lauren Moineau
9,483 PointsLauren Moineau
9,483 PointsHi. Does your app run OK or does it crash? As for the Log.d, could you paste your code here, please? Thanks