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

The android Log problem

The task is:

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

I get errror: "Bummer! 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."

With this code: <code>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); setContentView(R.layout.activity_main); Log.d(MainActivity, "Activity created!"); } } </code>

Can someone please hint or help me with this since im stuck :(

Thanks!

1 Answer

Solved it:

<html>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); setContentView(R.layout.activity_main); Log.d(TAG, "Activity created!"); } } </html>