0

I looked at this answer:

NullPointerException: name == null

And tried doing like this in my fragment XML:

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.OscarJunker.resturantlocaterexample.pcbuilderhandbook.pcbuilderhandbook.FrontFragment">

<!-- TODO: Update blank fragment layout -->
<fragment
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/front_fragment"
    android:name="com.OscarJunker.resturantlocaterexample.pcbuilderhandbook.pcbuilderhandbook.FrontFragment"
    />

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/hello_blank_fragment"
    android:layout_gravity="center_horizontal|top"
    />

but i get this error: java.lang.IllegalArgumentException: Binary XML file line #8

I'm trying to put my fragment in the app with transactions in java code

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<!-- As the main content view, the view below consumes the entire
     space available using match_parent in both dimensions. -->
<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

android:name="com.OscarJunker.resturantlocaterexample.pcbuilderhandbook.pcbuilderhandbook.FrontFragment"

<!-- android:layout_gravity="start" tells DrawerLayout to treat
     this as a sliding drawer on the left side for left-to-right
     languages and on the right side for right-to-left languages.
     If you're not building against API 17 or higher, use
     android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
     the container. -->
<fragment android:id="@+id/navigation_drawer"
    android:layout_width="@dimen/navigation_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:name="com.OscarJunker.resturantlocaterexample.pcbuilderhandbook.pcbuilderhandbook.NavigationDrawerFragment"
    tools:layout="@layout/fragment_navigation_drawer" />

Community
  • 1
  • 1
Chimpanse
  • 250
  • 1
  • 5
  • 17

1 Answers1

0

The layout you give here has a static fragment in it. You cannot replace it with transactions. Instead, you need to put a FrameLayout in your XML.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • sorry, i am confused, the the XML code is for the fragment i'm trying to put in my main activity. What do you mean by putting a framlayout in it, it already has? – Chimpanse Jul 16 '14 at 00:59
  • @OscarJunker You need one layout for your activity and another for your fragment. The one for your activity should have a FrameLayout which is a placeholder for the fragments you want to load dynamically. You should **not** have a `` tag in the layout for another fragment. – Code-Apprentice Jul 16 '14 at 01:10
  • i already have one in my main actvity that looks like this: I tried putting it there but got eror: .IllegalArgumentException: Binary XML file line #8: Duplicate id. it might be for my navigation drawer i'm not sure – Chimpanse Jul 16 '14 at 01:17
  • @OscarJunker Please edit your question to show both your layout files. – Code-Apprentice Jul 16 '14 at 01:22
  • @OscarJunker As I said earlier, you cannot have a `` tag inside the layout for another fragment. – Code-Apprentice Jul 16 '14 at 01:35
  • so the Framlayout in mainACtivty IS for the navigation drawer? should i then create a new framlayout inside the same XML? – Chimpanse Jul 16 '14 at 01:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/57358/discussion-between-code-apprentice-and-oscar-junker). – Code-Apprentice Jul 16 '14 at 01:43