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 Kotlin Testing and Debugging Writing to the Log

I cannot get the correct answer for Part 2, but I'm not sure why...

Part 2 of this challenge asks me to use a method to get the activity name instead of hard coding it. Following the example from the FunFacts project, I entered the following" val TAG = TreehouseActivity::class.simpleName

I get the following error: Bummer! TreehouseActivity.kt:10:11: error: type mismatch: inferred type is String? but String was expected Log.d(TAG, "Activity created!")

The instructions seems to suggest that we should call something like, TreehouseActivity.class.getSimpleName(). This is not how the logging was done in the example, and it throws an error when I try this approach in the FunFacts project. Am I making a silly mistake here, or is there something wrong with the challenge?

TreehouseActivity.kt
import android.app.Activity
import android.os.Bundle

class TreehouseActivity : Activity() {
  val TAG = TreehouseActivity::class.simpleName

  override fun onCreate(savedInstanceState: Bundle) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_treehouse)
    Log.d(TAG, "Activity created!")
  }
}