Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8237011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:19:41+00:00 2026-06-07T19:19:41+00:00

I’m just trying to follow along with the example code on android dev to

  • 0

I’m just trying to follow along with the example code on android dev to inflate a fragment in an activity. I have a more complicated project I’m working but I’m getting the same error as this simple one here. Can anyone point me in the right direction?

The class that extends fragment

package com.example.fragtest;


import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class FragOne extends Fragment {

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
    }
    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState){
        return inflater.inflate(R.layout.activity_main, container,false);
    }

}

The class that extends FragmentActivity

package com.example.fragtest;

import android.os.Bundle;
import android.view.Menu;
import android.support.v4.app.FragmentActivity;

public class MainActivity extends FragmentActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }



}

The xml where the fragment is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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" >

   <fragment android:name="com.example.fragtest.FragOne"
       android:id="@+id/frag"
       android:layout_width="match_parent"
       android:layout_height="match_parent" />

</LinearLayout>

The manifest where the activity name is set

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.fragtest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Here is the logcat output

07-17 23:45:09.053: E/AndroidRuntime(560): FATAL EXCEPTION: main
07-17 23:45:09.053: E/AndroidRuntime(560): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragtest/com.example.fragtest.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.os.Looper.loop(Looper.java:137)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.app.ActivityThread.main(ActivityThread.java:4340)
07-17 23:45:09.053: E/AndroidRuntime(560):  at java.lang.reflect.Method.invokeNative(Native Method)
07-17 23:45:09.053: E/AndroidRuntime(560):  at java.lang.reflect.Method.invoke(Method.java:511)
07-17 23:45:09.053: E/AndroidRuntime(560):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-17 23:45:09.053: E/AndroidRuntime(560):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-17 23:45:09.053: E/AndroidRuntime(560):  at dalvik.system.NativeStart.main(Native Method)
07-17 23:45:09.053: E/AndroidRuntime(560): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-17 23:45:09.053: E/AndroidRuntime(560):  at com.example.fragtest.FragOne.onCreateView(FragOne.java:18)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:846)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1160)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-17 23:45:09.053: E/AndroidRuntime(560):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.app.Activity.setContentView(Activity.java:1835)
07-17 23:45:09.053: E/AndroidRuntime(560):  at com.example.fragtest.MainActivity.onCreate(MainActivity.java:12)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.app.Activity.performCreate(Activity.java:4465)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
07-17 23:45:09.053: E/AndroidRuntime(560):  ... 11 more
07-17 23:45:09.053: E/AndroidRuntime(560): Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f080000, tag null, or parent id 0x0 with another fragment for com.example.fragtest.FragOne
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
07-17 23:45:09.053: E/AndroidRuntime(560):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
07-17 23:45:09.053: E/AndroidRuntime(560):  ... 30 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:19:43+00:00Added an answer on June 7, 2026 at 7:19 pm

    In your Class that extends FragmentActivity you are setting the view to an XML file titled activity_main. Inside of activity_main you have a reference to your Fragment code, com.example.fragtest.FragOne.
    When that XML is loaded, the code associated with com.example.fragtest.FragOne is executed. That Fragment‘s code returns a View with the R.id.activity_main.

    That XML file has a reference to the same Fragment code that had just instantiated it. You see the conundrum.

    To resolve your issue instance a new XML file (one that is not named activity_main) in your Fragment class. Instead of inflating activity_main inflate a separate XML (one that does not contain a reference to the code that called it). Effectively activity_main should be the container, this new layout (for instance fragment_layout) will be the UI portion.

    I like to think of it like this: Despite doctrine, a Fragment has three portions. The container Activity (this can, and in your case should, inflate a layout XML file via setContentView), the Fragment‘s java code (this can, and in your case should, inflate a layout….something other than activity_main), and that Fragment‘s associated XML file (the one that is inflated by your Fragment class, don’t include a cyclical reference back to it’s code).

    There are, of course, loopholes to these mantras but you get the drift?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.