Does anyone know why it fails to resolve it.
# android
t
Does anyone know why it fails to resolve it.
m
what’s line 41?
t
val textView: TextView = toolbar!!.findViewById(R.id.titleToolbar)
I am including toolbar layout like in my activities layout.
Copy code
<include
	android:id="@+id/tb_layout"
	layout="@layout/toolbar"
	android:layout_width="match_parent"
	android:layout_height="wrap_content" />
m
cool, could you please paste the toolbar layout as well?
t
m
are you able to ⌘ + click on
titleToolbar
on the
MainActivity.kt
?
t
When I runs it from Android Studio directly then it runs without an error.
m
oooh, that’s pretty odd
t
it givers an error when I build it using
gradlew build
This made me to unable to use dagger2 because without build it, dagger2 classes are not generating.
When I click on it then it navigates me to that view too
b
Why you are using
!!
is not kotlin idioms dude ^^
t
I should not, even though I should remove toolbar to get reference of title.
If I don't use !! then AS gives warning
m
technically just `findViewById(...)`should work
because you’re calling it inside an apply
t
Smart cast
Toolbar
is impossible ... so I used !! anyways I am removing just simply calling
findViewByID
m
but it probably won’t solve your issue
t
Yes. correct
I am using Kotlin extension too to get views reference.
I am including a layout in my activity layout. Do you know how to get reference directly.
As I am able to get activity layout directly like
nvView.setNavigationItemSelectedListener(this)
but not
Copy code
toolbar?.apply {
     titleToolbar.text = getString(R.string.tb_home)
}
m
you don’t need the
apply
here
just call titletoolbar directly, but make sure you’re importing the right layout file
t
I did this too
tbLayout.titleToolbar = getString(R.string.tb_home)
ah okay
lemme remove apply
Not working. Looks like bug in kotlin extension
I have toolbar layout in base module. I am trying to add this in feature module
May be because of this. I am importing my activity layout like
import kotlinx.android.synthetic.main.activity_main.*
and setting activity layout
setContentView(R.layout.activity_main)
m
that’s all good
but for the toolbar layout you need to import the kotlin extension file for its layout as well
t
but its in base module. How I can import it ? layout name is
toolbar.xml
this lists layouts
import kotlinx.android.synthetic.main.
which in my feature module, not base module, even though it should show
t
smells like an import issue. carefully comb through them and ensure everything is as expected
t
AS only suggests layouts which are in my feature module. it should suggests layouts which are in feature+base module
Uff I ended up by commenting it 😕 Idk how to fix it. don't know if it is bug, but it is likely