"Build a Simple iPhone App with Swift" was retired on May 31, 2020.

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 Basic Android Programming Initializing a Button

Hannah Lee
Hannah Lee
80,187 Points

Initialize the showFactButton variable using the findViewById() method like the TextView above it.

The ID for the button is showFactButton, and don't forget to cast it to a Button with as Button!

However, it gets "Unable to access jarfile test.jar" error!!!

FunFactsActivity.kt
import android.app.Activity
import android.os.Bundle
import android.widget.TextView
import android.widget.Button

class FunFactsActivity : Activity() {
  override fun onCreate(savedInstanceState: Bundle) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_fun_facts)

    // Declare our View variables and assign them the Views from the layout file
    val factLabel = findViewById(R.id.factTextView) as TextView
    Button showFactButton = (Button) findViewById(R.id.showFactButton);
  }
}

2 Answers

Hi Hannah. It's just that you initialized your showFactButton variable in Java. In this course, you need to do it in Kotlin.

I won't give you the answer but just follow the example of the line right above, for the factLabel variable:

val factLabel = findViewById(R.id.factTextView) as TextView

I'm sure you'll get it right. But if you need further help, ask away :)

you are not helping, tried many things and wont solve the problem, be explicit we are trying to learn, and getting more confused will actually kill the enthusiasm

Farai Ted Mandoreba, I'm sorry you see it as not helping nor being explicit. However, bear in mind that this question refers to the "Build a Simple App with Kotlin" course. I believe the questions you posted on the forum (which I answered) were related to the "Build a Simple App with Java" course. Different languages, but I know it's easy to miss when running a search. So this post will definitely not help you I'm afraid.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Sounds like it might be an issue that can be solved with simply a rebuild or a clean of your project in AS Studio. Try this and preview your project again and it should work. :-)