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 Build a Simple Android App with Java Testing and Debugging Writing to the Log

Nikki Wong
Nikki Wong
9,066 Points

Log.d(tag, msg)?? Why am I getting errors?

in my own android studio it removes the tag id automatically when I used TAG :

Log.d( TAG, "We're logging from the onCreate() method");

but here I tried: Log.d( tag: TAG, "We're logging from the onCreate() method");

as well as:

Log.d( TAG, "We're logging from the onCreate() method");

and I kept getting errors? Help?

com/teamtreehouse/TreehouseActivity.java
package com.teamtreehouse;

public class TreehouseActivity extends Activity {
  public static final String TAG = "TreehouseActivity";

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_treehouse);
    Log.d(tag: TAG, msg: "Activity created!");
  }
}

Please try this : Log.d(TAG, msg:"Activity created!");

2 Answers

Seth Kroger
Seth Kroger
56,414 Points

If you are trying to mimic what you see in Android Studio, you should know that the "tag:" and "msg:" are not part of the code you write. Notice how they are highlighted and in a different font in AS. They are also not editable. It's additional guidance from AS telling you what arguments the method expects. You do not type them in yourself and don't appear in your code outside of AS.

Nikki Wong
Nikki Wong
9,066 Points

Thanks Seth!! I know that, but I don't know how to write it for the challenge as they don't automatically pop up when I type Log.d ?

Seth Kroger
Seth Kroger
56,414 Points
Log.d(TAG, "Activity created!");

Just the two values separated by a comma.

Nikki Wong
Nikki Wong
9,066 Points

Thanks a mil Seth! Was a bit confusing for a beginner using Android Studio

Nikki Wong
Nikki Wong
9,066 Points

These are the errors I keep getting?

./com/teamtreehouse/TreehouseActivity.java:11: error: ')' expected Log.d(TAG, msg:"Activity created!"); ^ ./com/teamtreehouse/TreehouseActivity.java:11: error: not a statement Log.d(TAG, msg:"Activity created!"); ^ ./com/teamtreehouse/TreehouseActivity.java:11: error: ';' expected Log.d(TAG, msg:"Activity created!"); ^ ./com/teamtreehouse/TreehouseActivity.java:11: error: cannot find symbol Log.d(TAG, msg:"Activity created!"); ^ symbol: variable msg location: class TreehouseActivity 4 errors