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

moetouban

12/01/2017, 12:15 PM
Hi, quick question does anyone know how to use extensions to reference a view included in another view (include) ? am getting IllegalStateException.
m

marcinmoskala

12/01/2017, 12:37 PM
Can you be more specific?
m

moetouban

12/01/2017, 12:43 PM
let say i have my view which includes another view using (include tag). Now if you want to reference any view inside your layout you can do that by importing your layout ex.
Copy code
import kotlinx.android.synthetic.main.activity_login.*
and this is fine. But, if you want to reference a view inside the included view you get NullPointerException.
n

nil2l

12/01/2017, 12:44 PM
<include> ’ed?
m

moetouban

12/01/2017, 12:45 PM
yes
n

nil2l

12/01/2017, 12:45 PM
import kotlinx.android.synthetic.main.common_view.*
so import both views
m

moetouban

12/01/2017, 12:47 PM
that's not working it's giving me NullPointerException
m

marcinmoskala

12/01/2017, 1:27 PM
If it is activity then It means that one of this views is not shown
findViewById(id)
returns null
l

lupajz

12/01/2017, 3:36 PM
Did you set id to your include tag?
m

moetouban

12/01/2017, 3:39 PM
yes