java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTextColor(android.content.res.ColorStateList)' on a null object reference
viewHolder.name.setTextColor(selectedTextColor);
in BaseDescribeableDrawerItem when call bindViewHelper(viewHolder). When i try cath it, instant app can start normally (but draweritem doesn' have name and description)@sonhvp sorry for the late answer.
I am not sure how this could be an issue of the library :/.
The library uses normal layouts, and accesses the views of the layout via their identifier. as it is supposed to be.
could it be some issue with the setup of the instant app? is the drawer not in the right module, and not shipped?
or your item being in the wrong module missing the layout? or such?
After tested many times. I don't think the library is the reason cause crash. As you mentioned, the library uses normal layouts, and accesses the views of the layout via their identifier. I checked and tested so many times but can't understand why. I think the instant app feature has something wrong. If you want to see the issue, you can have a look at my test repository: https://github.com/sonhvp/test_project.
Thanks for your support.
@sonhvp so I believe I figured out what is going on here.
So the id's of the materialDrawer
are in the com.mikepenz.materialdrawer.R
class. Wheras your id's are in the com.sonhvp.test
class. So when you then use your own xml
file, the id's are in your namespace, but the BaseViewHolder
tries to find the ids in the materialdrawer
namespace. As such it will not be able to find the views and they stay null.
To solve the problem just add:
init {
this.icon = view.findViewById(R.id.material_drawer_icon)
this.name = view.findViewById(R.id.material_drawer_name)
this.description = view.findViewById(R.id.material_drawer_description)
}
to your ViewHolder
in the OverflowMenuDrawerItem
(ensure it is the R
of your package)
If I am not wrong it works for the app because the R
fields for identifiers are there still merged, and same identifiers are just merged and will be the same id. Whereas for instantapps this does not happen. (at least this is my assumption)
In addition I believe google's plan is to have the same for normal modules at some point in the future too. basically namespacing all identifiers and layouts and prevent them being overwritten from a different module.