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
Muhammad Sodikin
2,815 PointsStoryActivity.java error
Hi, I have issue on this code: What would you do to solve this?
<p> @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_story);
Intent intent = getIntent();
String name = intent.getStringExtra(getString(R.string.key_name));
if (name == null) {
name = "Friend";
}
}
< Log.d(TAG, name); /p>
the TAG has error and give Log Cat of
```Error:(14, 37) error: '{' expected Error:(14, 63) error: <identifier> expected Error:(14, 64) error: invalid method declaration; return type required Error:(29, 14) error: <identifier> expected Error:(29, 18) error: <identifier> expected Error:(29, 24) error: <identifier> expected Error:(31, 6) error: reached end of file while parsing Error:Execution failed for task ':app:compileDebugJava'.
Compilation failed; see the compiler error output for details.```
1 Answer
Liam Peters
8,792 PointsHi Muhammad, Your log statement needs to be within the onCreate() method - Currently it sits outside the closing } for the onCreate() Method
Muhammad Sodikin
2,815 PointsMuhammad Sodikin
2,815 PointsYes, okay changes has made. and yes.
But still the TAG is still shown red.
Thx Liam :)
Liam Peters
8,792 PointsLiam Peters
8,792 PointsHave you defined TAG as a member variable (at the top - outside a method but within a class). Should be something like:
private static final String TAG = Mainactivity.class.getsimplename();Muhammad Sodikin
2,815 PointsMuhammad Sodikin
2,815 PointsGot it. Yeah. Tengsss a lot.