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 Improving Our Code Creating a New Class

What am I doing wrong?

I think my code is ok, but I'm still getting an error.

PictureBook.kt
public fun PictureBook(){

  var title : String = "Android Adventures"
}

Hi! I tried this question just now. This passes:

public class PictureBook{
    val title = "Android Adventures"
}

You would want to use val instead of var whenever possible. This will lead to more robust code. Use var only when you absolutely need to change the variable.

3 Answers

You should be using class instead of fun.

Try var title = "Android Adventures";

:)

public fun PictureBook(){

var title = "Android Adventures"
}

I got:

Bummer! Make sure PictureBook has a 'title' property and that it's a String

Hmm... Mine passes. I do notice you forgot the semi-colon after "Android Adventures";

public class PictureBook(){
  var title = "Android Adventures";
}

no. in Kotlin, "; " is not required always use val where possible. Declare var only when you absolutely need to