Reputation: 9263
this is my first question
In Java I have never had this problem before.
I spent two days because I had an issue just on design mode on Android studio inflating a CustomView with kotlin. I had a findByView = null after the inflate. Running the app, all is right
View.inflate(context, R.layout.widget_navigation_section_button, this)
mLabel = findViewById(R.id.navigation_section_title)
mLabel.setText("something")
That throws a NPE (for real in kotlin: kotlin.TypeCastException: null cannot be cast to non-null type android.widget.TextView at ... $mLabel$2.invoke(CustomView.kt:22))
Normally, I use a <layout>[.<where_container>].<name>
pattern to name ids and string on XMls (ex: android:id="@+id/main.description_container.title"
)
This is translated automatically in R.id.main_description_container_title
(notice dots become underscores) in code
The issue was solved when I replace these dots with underscores manually in the XML
I was looking for name conventions explaining why dots should not used in ids or string naming, but without success. I want to know what is the real issue with this name convention. This should be really avoid it ?
Should I just drop the idea and just user underscores ? Looking at it is an issue just on kotlin, maybe some gradle configuration ther ?
Thank you in advance
Upvotes: 1
Views: 2017
Reputation: 11165
You can't use dots, because following expression R.id.main.description_container.title
will try to find member main
which has type Int
and then try find property description_container
, but Int
doesn't have such property
Upvotes: 3