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 Accessing Views in Code: Declaring Variables

I am using android studio 2.3.3. To declare view variables using 'var' keyword. It is not supporting.

in MainActivity

private var factTextView: TextView? = null

error - cannot resolve symbol var error - : error - ? = null

Hi!

Could you please give us a copy of your code so we can check it out? It would be great and would help us solve your problem faster.

Thanks!

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

In 2.3 you probably didn't have the checkbox on the New Project dialog to configure for Kotlin at the start. In the menu at the top click Tools -> Kotlin -> Configure Kotlin in Project -> Android and Gradle. Then do a Gradle Sync. If your Activity is a Java file (the name ends in .java instead of .kt) go to the Menu and click Code -> Convert Java File to Kotlin File (should be at the bottom)

Thanks I will try