0

I've started programming an app for android importing the Navigation Drawer code sample from android studio. Running it I got the error

Error:(43) No resource identifier found for attribute 'layoutManager' in package 'com.example.android.navigationdrawer'

I've followed the instructions found in Error 'No resource identifier found' with Android sample project but I got the following error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.navigationdrawer/com.example.android.navigationdrawer.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference

I couldn't find another answer that I can adapt since my skills are quite basic.

The only differences from the original NavigationDrawer sample code are:

I removed from activity_navigation_drawer.xml:

app:layoutManager="LinearLayoutManager"

I added the last two lines in this NavigationDrawerActivity snippet

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_drawer);

    mTitle = mDrawerTitle = getTitle();
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (RecyclerView) findViewById(R.id.left_drawer);

    LinearLayoutManager mLinearLayoutmanager = new LinearLayoutManager(this);
    mDrawerList.setLayoutManager(mLinearLayoutmanager);
    ....

Thanks in advance for the help

Community
  • 1
  • 1
Iaaf
  • 1
  • 1
  • what's exactly the question? – Blackbelt Oct 13 '15 at 19:51
  • How do I fix the null object reference, or more in general how do I make the sample work? – Iaaf Oct 13 '15 at 20:28
  • @Iaaf The null object reference means that you attempted to set the layout of the `mDrawerList` before it has been _instantiated_ i.e. the `mDrawerList` does not exist and you're trying to set the `mLinearLayoutManager` on it. Basically, you probably added the 2 lines (LinearLayoutManager) above the `mDrawerList = (RecyclerView)...` contrary to what you have shown in the snippet. – Brian Kinyua Oct 18 '15 at 09:33

1 Answers1

-1

this Error means xml file dismiss or not define Create xml file or import

Alen Smith
  • 35
  • 8