Hi.
im trying to implement the standard drawer in my app (the one that shows up when you open the sample app), however i am getting a ResourceNotFoundException and i have no idea why.
this is my code:
IProfile profile = new ProfileDrawerItem().withName("Homer Simpson").withEmail("[email protected]").withIcon("http://www.yourtv.com.au/img/blog/homer-simpson.jpg");
mHeader = new AccountHeaderBuilder()
.withActivity(this)
.withTranslucentStatusBar(true)
// .withHeaderBackground(R.drawable.header)
.addProfiles(profile)
.withSavedInstance(savedInstanceState)
.build();
mDrawer = new DrawerBuilder()
.withActivity(this)
.withHasStableIds(true)
.withAccountHeader(mHeader)
.addDrawerItems(new PrimaryDrawerItem().withName("inbox").withIdentifier(DRAWERITEM_ID_INBOX).withSelectable(false),
new PrimaryDrawerItem().withName("therapists").withIdentifier(DRAWERITEM_ID_THERAPISTS).withSelectable(false),
new PrimaryDrawerItem().withName("my treatments").withIdentifier(DRAWERITEM_ID_MYTREATMENTS).withSelectable(false),
new PrimaryDrawerItem().withName("evaluation").withIdentifier(DRAWERITEM_ID_EVALUATION).withSelectable(false),
new PrimaryDrawerItem().withName("diagnosis").withIdentifier(DRAWERITEM_ID_DIAGNOSIS).withSelectable(false),
new PrimaryDrawerItem().withName("calendar").withIdentifier(DRAWERITEM_ID_CALENDAR).withSelectable(false),
new PrimaryDrawerItem().withName("logout").withIdentifier(DRAWERITEM_ID_LOGOUT).withSelectable(false))
.withOnDrawerItemClickListener(this)
.withSavedInstance(savedInstanceState)
.withShowDrawerOnFirstLaunch(true)
.build();
and this is the exception im getting when trying to run:
03-16 17:33:00.454 5022-5022/com.example.videotherapystudio E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.videotherapystudio, PID: 5022
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1269)
at android.content.res.Resources.getDrawable(Resources.java:769)
at android.content.Context.getDrawable(Context.java:402)
at android.support.v4.content.ContextCompatApi21.getDrawable(ContextCompatApi21.java:26)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:321)
at com.mikepenz.materialize.util.UIUtils.getSelectableBackground(UIUtils.java:353)
at com.mikepenz.materialize.util.UIUtils.getSelectableBackground(UIUtils.java:285)
at com.mikepenz.materialdrawer.model.BasePrimaryDrawerItem.bindViewHelper(BasePrimaryDrawerItem.java:78)
at com.mikepenz.materialdrawer.model.PrimaryDrawerItem.bindView(PrimaryDrawerItem.java:69)
at com.mikepenz.materialdrawer.model.PrimaryDrawerItem.bindView(PrimaryDrawerItem.java:18)
at com.mikepenz.fastadapter.FastAdapter$OnBindViewHolderListenerImpl.onBindViewHolder(FastAdapter.java:1287)
at com.mikepenz.fastadapter.FastAdapter.onBindViewHolder(FastAdapter.java:413)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5453)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5486)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4723)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4599)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1988)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1384)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1347)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3003)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2881)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3265)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4966)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4966)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1211)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4966)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4966)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1705)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1559)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1468)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4966)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:15631)
at android.view.ViewGroup.layout(ViewGroup.java:4966)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2101)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1858)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1077)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5845)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.
i tried to eliminate this error by removing anything that calls for a resource (e.g. no drawable background for header, and hard-coded strings) but to no use... still getting the above error.
i am using version 5.1.3
please help
@or-dvir on which device do you test? which android version? which support libraries?
It can't resolve the following: R.attr.selectableItemBackground. This is a valid resource, so it seems there is a misconfiguration somewhere
device is LG G3 android version 5.0
what does it mean there is a misconfiguration somewhere? how can i fix this?
p.s.
could it have anything to do with the fact that im using a fragment activity?
@or-dvir you already cleaned and rebuilt the project?
Which support libraries do you use?
yes. i did clean and rebuild, and still getting this exception.
i am using both v4 and v7 support libraries in my app
@or-dvir which version of those?
If you try the sample app will it crash too?
sorry... miss understood your question.
this is what im using:
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
although i do receive a warning saying there is a new version, it says it is an alpha version,
so i don't want to use it (i need stable version).
sample app does not crash.
the layout for my activity is actually a viewpager - could that be the problem?
@or-dvir the latest version of the MaterialDrawer requires the latest (stable) support libraries v23.2.1
(you get the alpha warning because there is the Android N alpha version of the support libraries)
I think you should remember also to compile the app using the 23 lib.
@christianguevara thanks for adding this detail
ok... ill see if that works when im back at work next week
@or-dvir ok great. fine. please report back here if it worked ;)
I just had exactly the same problem and in my case it was solvable by adding a android:theme="@style/MaterialDrawerTheme.*" attribute to the activity tag in the AndroidManifest.xml.
Maybe the same in your case?
The cause was hard to find though and i was only lucky, because the stack trace is too long. Maybe consider it a bug...?
btw: Awesome library, thank you so much! :-)
Cheers
@pokerazor oh you might be right. This attribute is only there for the AppCompat themes and all themes which extend the AppCompat theme.
It's no bug, but I should note that the theme has to be an AppCompat theme, or a child from it, like the MaterialDrawerTheme.*
@christianguevara i am using "compileSdkVersion 23"
@mikepenz changing to support libraries 23.2.1 does not fix the problem
changing the theme worked!!!
now i just have to find one that fits my app AND inherits from appcompat.
thank you!
edit: i can't find a way to mark "accepted answer". how do i do that?
@or-dvir just for for curiosity, which theme did you use before?
EDIT: I already closed the issue. So it's fine ;)
i was using @android:style/Theme.Holo.Light.NoActionBar
@or-dvir oh ok. Yeah it is not recommended to use this theme :D. The AppCompat theme will give your app a far better look across different API versions
Most helpful comment
I just had exactly the same problem and in my case it was solvable by adding a
android:theme="@style/MaterialDrawerTheme.*"attribute to the activity tag in the AndroidManifest.xml.Maybe the same in your case?
The cause was hard to find though and i was only lucky, because the stack trace is too long. Maybe consider it a bug...?
btw: Awesome library, thank you so much! :-)
Cheers