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

  • Home
  • SEARCH
  • 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 8135387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:24:08+00:00 2026-06-06T10:24:08+00:00

I want to inflate a LinearLayout into a fragment in the onCreateView method. But

  • 0

I want to inflate a LinearLayout into a fragment in the “onCreateView” method. But I have always the same error:

"android.view.InflateException: Binary XML file line #7: Error inflating class fragment"

I am using the android.support.v4.app.FragmentActivity in a "libs" folder.

Main activity:

public class GeofranceDeptActivity extends FragmentActivity{
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dept);

    }
}

The main xml file dept:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <fragment class="dauran.geofrance.DeptFragment"
            android:id="@+id/depts" android:layout_weight="1"
            android:layout_width="0px"
            android:layout_height="match_parent"> 
            </fragment>

    <FrameLayout android:id="@+id/detailsdept" android:layout_weight="1"
            android:layout_width="0px"
            android:layout_height="match_parent" />

</LinearLayout>

The class for the fragment DeptFragment:

public class DeptFragment extends Fragment implements OnTouchListener{

    Context mContext = getActivity();

    boolean mDualPane;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        if (container == null) {
              return null;
            }

    return (LinearLayout)inflater.inflate(R.layout.dept_fragment, container, false);
        }


    @Override
    public void onActivityCreated(Bundle savedState) {
        ................etc

The xml file dept_fragment that I want to inflate :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" >
    <ImageView
        android:id="@+id/targetDeptImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/region_france_grand" />

    <ImageView
        android:id="@+id/cacheDeptImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/region_france_grand" />
    <Spinner
        android:id="@+id/sDepartement"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignRight="@+id/targetImage" />

</RelativeLayout>
</LinearLayout>

The Logcat:

06-26 19:02:27.940: E/AndroidRuntime(11993): FATAL EXCEPTION: main
06-26 19:02:27.940: E/AndroidRuntime(11993): java.lang.RuntimeException: Unable to start activity ComponentInfo{dauran.geofrance/dauran.geofrance.GeofranceDeptActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.os.Looper.loop(Looper.java:137)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.app.ActivityThread.main(ActivityThread.java:4424)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at java.lang.reflect.Method.invokeNative(Native Method)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at java.lang.reflect.Method.invoke(Method.java:511)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at dalvik.system.NativeStart.main(Native Method)
06-26 19:02:27.940: E/AndroidRuntime(11993): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.app.Activity.setContentView(Activity.java:1835)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at dauran.geofrance.GeofranceDeptActivity.onCreate(GeofranceDeptActivity.java:10)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.app.Activity.performCreate(Activity.java:4465)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-26 19:02:27.940: E/AndroidRuntime(11993):    ... 11 more
06-26 19:02:27.940: E/AndroidRuntime(11993): Caused by: java.lang.IllegalStateException: Fragment dauran.geofrance.DeptFragment did not create a view.
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:293)
06-26 19:02:27.940: E/AndroidRuntime(11993):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
  • 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-06T10:24:11+00:00Added an answer on June 6, 2026 at 10:24 am

    The Logcat probably says more then android.view.InflateException: Binary XML file line #7: Error inflating class fragment(check below to see if you don’t have an instantiation exception, maybe you could add the full exception?). After looking at your code I would assume that your DeptFragment isn’t situated in the dauran.geofrance package and because of this android can’t find it.

    Also, there is no need to test for null the container parameter:

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
        return inflater.inflate(R.layout.dept_fragment, container, false);
    }
    

    Also, I don’t see the need for wrapping the RelativeLayout with a LinearLayout in the R.layout.deptfragment:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">
        <ImageView
            android:id="@+id/targetDeptImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/region_france_grand" />
    
        <ImageView
            android:id="@+id/cacheDeptImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/region_france_grand" />
        <Spinner
            android:id="@+id/sDepartement"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignRight="@+id/targetImage" />
    
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to inflate a childView of ExpandableChildView component. Code: public View getChildView(int groupPosition,
Inside a fragment, I have a button which I want to trigger the filling
I have the following code in resultlookup.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:id=@+id/layoutResultOuter
I have created a custom view for my Toast Messages. I want my toast
hi i want to draw path into canvas but it does not do anything,
I want to add multiple View in a LinearLayout . Here is the code
I have three arrays of String data and I want to inflate them in
I'm new to developing with android. I have a grid contained in a LinearLayout
I want to inflate single cells of a TableLayout : The information I want
Want to run javascript function from parent window in child window Example I have

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.