0

So I'm working on an app for a friend and it keeps crashing and is unable to run on my device (OnePlus One).

I keep getting an error here saying "No view found for id": Logcat view for Error

I have two classes; a NavigationDrawer class (which is my essentially my MainActivity):

Java --- http://pastebin.com/4BiYvxiS | XML --- http://pastebin.com/Fnat83uf

And a class named StartingFragment (which I want to be the main view when the drawer is closed/not active).

Java --- http://pastebin.com/HNeHzx1h | XML --- http://pastebin.com/2viTEWR8

Here is the code in which there is an error (from NavDrawer.java):

        /** Swaps fragments in the main content view */
        /** Starts an Activity when item is clicked */
        private void selectItem(int position) {
                // Create a new fragment and specify the tea type
                // to show based on position
                Fragment fragment = new StartingFragment();
                Bundle args = new Bundle();
                args.putInt(StartingFragment.TEA_TYPE_POS, position);
                fragment.setArguments(args);

                // Insert the fragment by replacing any existing fragment
                FragmentManager fragManager = getFragmentManager();
                fragManager.beginTransaction().replace(R.id.starting_fragment, fragment)
                                .commit();

                // Highlight the selected item, update the title, and close the drawer
                mDrawerList.setItemChecked(position, true);
                setTitle(navDrawerTitles[position]);
                navDrawerLayout.closeDrawer(mDrawerList);

        }

I've looked all over StackOverflow and I see how other's are getting this error, but I'm not entirely sure of why I keep getting this error, or how to fix it.

I looked at this question here: https://stackoverflow.com/a/8158916 and I see that R.id.starting_fragment should be a child of the R.layout.nav_drawer.

However, I don't know what to adjust in my code. Should I remove the Buttons I have and then have fragment code in my nav_drawer.xml? Such as this:

<fragment android:name="com.fv4.app.StartingFragment"
              android:id="@+id/starting_fragment"
              android:layout_width="0dp"
              android:layout_height="match_parent" />

Or really...what should I be replacing R.id.starting_fragment with in my code?

Community
  • 1
  • 1
freddiev4
  • 2,243
  • 2
  • 23
  • 44

1 Answers1

0

In the xml you gave for your activity there's no nothing with the id 'starting_fragment' therefore nothing to replace, in the xml for the activity there needs to be a view/layout/fragmentContainer with the id 'starting_fragment'. Also you're a bit confused, the Id in the .replace() method represents the thing you're going to replace not the layout of the fragment

Simple fix

in xml for the Activity create a frameLayout, give it the id 'fragment_replace'

Change .replace(R.id.starting_fragment,fragment) to .replace(R.id.fragment_replace,fragment)

steff_bdh
  • 969
  • 2
  • 12
  • 30
  • Ahh OK I see now (I think). That's where I was confused. OK well I adjusted the FrameLayout, but now I have this error (I adjusted the code in pastebin as well): http://puu.sh/dOpeZ/5ae8145f63.png – freddiev4 Dec 29 '14 at 18:31
  • Of course, Java has to throw in a NullPointer so... where do I go from here? – freddiev4 Dec 29 '14 at 18:45
  • is that the entire stack trace, doesn't it show you at which line you got the NPE – steff_bdh Dec 29 '14 at 19:25
  • This is the the entire thing printed out on Logcat: http://puu.sh/dOxeF/7d4c78c097.png ---> http://puu.sh/dOxiP/bb04347bd9.png – freddiev4 Dec 29 '14 at 19:28