https://kotlinlang.org logo
#android
Title
# android
t

tgmcians

09/06/2017, 2:16 PM
Does anyone know why it fails to resolve it.
m

menegatti

09/06/2017, 2:17 PM
what’s line 41?
t

tgmcians

09/06/2017, 2:18 PM
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

menegatti

09/06/2017, 2:21 PM
cool, could you please paste the toolbar layout as well?
t

tgmcians

09/06/2017, 2:22 PM
m

menegatti

09/06/2017, 2:24 PM
are you able to ⌘ + click on
titleToolbar
on the
MainActivity.kt
?
t

tgmcians

09/06/2017, 2:25 PM
When I runs it from Android Studio directly then it runs without an error.
m

menegatti

09/06/2017, 2:25 PM
oooh, that’s pretty odd
t

tgmcians

09/06/2017, 2:25 PM
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

budioktaviyan

09/06/2017, 2:35 PM
Why you are using
!!
is not kotlin idioms dude ^^
t

tgmcians

09/06/2017, 2:36 PM
I should not, even though I should remove toolbar to get reference of title.
If I don't use !! then AS gives warning
m

menegatti

09/06/2017, 2:37 PM
technically just `findViewById(...)`should work
because you’re calling it inside an apply
t

tgmcians

09/06/2017, 2:37 PM
Smart cast
Toolbar
is impossible ... so I used !! anyways I am removing just simply calling
findViewByID
m

menegatti

09/06/2017, 2:38 PM
but it probably won’t solve your issue
t

tgmcians

09/06/2017, 2:39 PM
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

menegatti

09/06/2017, 2:43 PM
you don’t need the
apply
here
just call titletoolbar directly, but make sure you’re importing the right layout file
t

tgmcians

09/06/2017, 2:44 PM
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

menegatti

09/06/2017, 2:50 PM
that’s all good
but for the toolbar layout you need to import the kotlin extension file for its layout as well
t

tgmcians

09/06/2017, 2:52 PM
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

trevjones

09/06/2017, 3:02 PM
smells like an import issue. carefully comb through them and ensure everything is as expected
t

tgmcians

09/06/2017, 3:05 PM
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