Butterknife: @BindColor fields must not be private or static (Kotlin)

Created on 18 May 2017  路  8Comments  路  Source: JakeWharton/butterknife

Hey there,

This is an issue that I see when using butterknife with Kotlin. It occurs with the following:

//These are broken, I believe so is @BindFloat
@BindInt(R.integer.some_int) var someInt: Int = 0
@BindDimen(R.dimen.some_dimen) var someDimen: Int = 0
@BindColor(R.color.colorPrimary) var colorPrimary: Int = 0
@BindBool(R.bool.some_bool) var someBool: Boolean = false

screen shot 2017-05-17 at 10 34 29 pm

Here is a project that produces these errors
https://github.com/Jawnnypoo/ButterknifeBindFailure

Most helpful comment

@Jawnnypoo, The issue is the same as described here.

That's a property whose backing field is private. Add @JvmField to generate a public field instead.

All 8 comments

We are also having this issue. With latest Android Studio 3.0 preview and latest butterknife release

Good to know. Just to confirm, I tested this with a few ButterKnife versions including 8.0.0 and still had the error, so I think this is independent of the version of ButterKnife (past 8.0.0 when this feature was added) and Android Studio.

@Jawnnypoo, The issue is the same as described here.

That's a property whose backing field is private. Add @JvmField to generate a public field instead.

Ahhh good stuff @Ilya-Gh thanks. Hopefully others will find this issue when they run into this then! 馃槃

I defined my var with _lateinit_ and they work..

Either @JvmField or lateinit work for me, but YMMV if the property must not be nullable.

I replaced internal var (\w+): (\w+)(\? = null) with lateinit var $1: $2 and it worked xD

@BindView(R.id.myView)
@JvmField
var myView: View? = null

or

@BindView(R.id.myView)
lateinit var myView: View
Was this page helpful?
0 / 5 - 0 ratings