Android Build a Simple Android App with Java Testing and Debugging Writing to the Log

Nikki Wong
Nikki Wong
9,065 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!");
  }
}
Burhanuddin Shabbir
Burhanuddin Shabbir
4,615 Points

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

2 Answers

Seth Kroger
MOD
Seth Kroger
Treehouse Moderator 56,252 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,065 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
Treehouse Moderator 56,252 Points
Log.d(TAG, "Activity created!");

Just the two values separated by a comma.

Nikki Wong
Nikki Wong
9,065 Points

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

Nikki Wong
Nikki Wong
9,065 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