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!
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

Milo Joseph
3,121 PointsHelp with using the Log function in Android
Inside the 'onCreate()' method (after the 'setContentView()' call), log the message "Activity created!" using the Log debug method (remember that it's just one letter). The 1st parameter should be "MainActivity", but use the member variable instead of typing it out a second time. The 2nd parameter is the message "Activity created!"

Milo Joseph
3,121 Pointspackage com.example;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
public static final String TAG = "MainActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

Milo Joseph
3,121 Pointssuper . onCreate(savedInstanceState) log.d ("MainActivity","Activity created!");
2 Answers

Joakim Andersson
Courses Plus Student 2,714 Pointspackage com.example;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
public static final String TAG = "MainActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.D(TAG, "Activity created!");
}
}
Im getting the error message: Compilation Error! The Log debug call must be inside the onCreate() method, and don't forget 'Log' before the method call since it's a static method of the Log class.
Please hint me :)

Ben Jakuben
Treehouse TeacherThat capital "D" in there isn't doing you any favors.
The naming convention in Java is that Class names begin with capital letters and pretty much everything else (method names and variable names) begin with lowercase letters (with some exceptions, of course).

Ben Jakuben
Treehouse TeacherSo with the line you pasted, it looks like some of the original code was deleted (the semicolon at the end of the onCreate() call and the setContentView line). Your Log statement needs to start with a capital L.

Milo Joseph
3,121 PointsBummer! Make sure you call the Log.d() method at the end of the onCreate() method!
package com.example;
import android.app.Activity; import android.os.Bundle; import android.util.Log;
public class MainActivity extends Activity {
public static final String TAG = "MainActivity";
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d("MainActivity","Activity created!"); setContentView(R.layout.activity_main);
} }

Ben Jakuben
Treehouse TeacherCheck out the instructions again, specifically this part: "(after the 'setContentView()' call), log the message..."
Ben Jakuben
Treehouse TeacherBen Jakuben
Treehouse TeacherHi Milo,
Can you paste your code in here so we can see what is wrong? Or if you have any specific questions do let us know.