Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

If you click on fragment A, Fragment B would show some text. Only it crashes saying: android.view.InflateException: Binary XML file line #56: Binary XML file line #56: Error inflating class fragment.. Having shearched for 2 days on stack, I really cannot find the problem :s

Log:

RuntimeException: Unable to start activity ComponentInfo{be.ehb.dt.taakandroid/be.ehb.dt.taakandroid.HowTo}: android.view.InflateException: Binary XML file line #56: Binary XML file line #56: Error inflating class fragment
                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                     at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                     at android.os.Looper.loop(Looper.java:148)
                                                                     at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                  Caused by: android.view.InflateException: Binary XML file line #56: Binary XML file line #56: Error inflating class fragment
                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                                     at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
                                                                     at android.app.Activity.setContentView(Activity.java:2166)
                                                                     at be.ehb.dt.taakandroid.HowTo.onCreate(HowTo.java:19)
                                                                     at android.app.Activity.performCreate(Activity.java:6237)
                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                     at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                     at android.os.Looper.loop(Looper.java:148) 
                                                                     at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                     at java.lang.reflect.Method.invoke(Native Method) 
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                  Caused by: android.view.InflateException: Binary XML file line #56: Error inflating class fragment
                                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
                                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                                                                     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                     at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
                                                                     at android.app.Activity.setContentView(Activity.java:2166) 
                                                                     at be.ehb.dt.taakandroid.HowTo.onCreate(HowTo.java:19) 
                                                                     at android.app.Activity.performCreate(Activity.java:6237) 
                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                     at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                     at android.os.Looper.loop(Looper.java:148) 
                                                                     at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                     at java.lang.reflect.Method.invoke(Native Method) 
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                  Caused by: java.lang.IllegalStateException: Fragment android.support.v4.app.DialogFragment did not create a view.
                                                                     at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2314)
                                                                     at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
                                                                     at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:314)
                                                                     at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)
                                                                     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
                                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
                                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                                                                     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                     at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
                                                                     at android.app.Activity.setContentView(Activity.java:2166) 
                                                                     at be.ehb.dt.taakandroid.HowTo.onCreate(HowTo.java:19) 
                                                                     at android.app.Activity.performCreate(Activity.java:6237) 
                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                     at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                     at android.os.Looper.loop(Looper.java:148) 
                                                                     at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                     at java.lang.reflect.Method.invoke(Native Method) 
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

Manifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="be.ehb.dt.taakandroid">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.NoActionBar">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

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

</manifest>

Class that runs both fragments:

package be.ehb.dt.taakandroid;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

import static be.ehb.dt.taakandroid.R.id.fragment2;

public class HowTo extends FragmentActivity implements Communicator{
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.howtoshop);

    ImageButton buttonback = (ImageButton) findViewById(R.id.arrowback);

    buttonback.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(HowTo.this, MainActivity.class));
        }
    });

    Button howTo = (Button) findViewById(R.id.HowTo);

    howTo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=r2sCq3_cBQ4")));
        }
    });

}
@Override
public void respond(int i) {
    android.support.v4.app.FragmentManager manager=getSupportFragmentManager();
    FragmentB f2= (FragmentB) manager.findFragmentById(fragment2);
    f2.ChangeData(i);

}

}

HowTo.xml:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000">

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearTop"
        android:orientation="vertical">



        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/imageBanner"
            android:src="@drawable/header2"
            android:layout_gravity="center_vertical"
            android:scaleType="fitXY"/>

        <ImageButton
            android:layout_width="51dp"
            android:layout_height="51dp"
            android:id="@+id/arrowback"
            android:src="@drawable/arrowback"
            android:layout_gravity="center_vertical|left"
            android:layout_marginRight="0dp"
            android:adjustViewBounds="true"
            android:padding="5dp"
            android:scaleType="fitCenter"
            android:focusableInTouchMode="false"
            android:background="#00ffffff" />


    </FrameLayout>

    <Button
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:text="How To Shop Video"
        android:id="@+id/HowTo"
        android:background="#ff0000"
        android:textAlignment="center"
        android:textColor="#ffffff"
        android:textSize="30dp"
        android:gravity="center_vertical" />

    <fragment
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:name="android.support.v4.app.ListFragment"
        android:id="@+id/fragment" />

    <fragment
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:name="android.support.v4.app.DialogFragment"
        android:id="@+id/fragment2" />

</LinearLayout>

Fragment A class:

package be.ehb.dt.taakandroid;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class FragmentA extends Fragment implements          AdapterView.OnItemClickListener {
ListView list;
Communicator communicator;

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

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    communicator= (Communicator) getActivity();
    list= (ListView) getActivity().findViewById(R.id.listView);
    ArrayAdapter adapter= ArrayAdapter.createFromResource(getActivity(),R.array.titels, android.R.layout.simple_expandable_list_item_1);
    list.setAdapter(adapter);
    list.setOnItemClickListener(this);
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int i, long l) {
    communicator.respond(i);
}
}

Fragment_a.xml:

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

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/listView"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>

Fragment B class:

package be.ehb.dt.taakandroid;
   import android.content.res.Resources;
   import android.os.Bundle;
   import android.support.v4.app.Fragment;
   import android.view.LayoutInflater;
   import android.view.View;
   import android.view.ViewGroup;
   import android.widget.TextView;

   public class FragmentB extends Fragment{
    TextView text;

    public View onCreatewView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

       final View view= inflater.inflate(R.layout.fragment_b,container,false);
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        text= (TextView) getActivity().findViewById(R.id.textView);
    }

    public void ChangeData(int i){
        Resources res =getResources();
        String[] antwoorden = res.getStringArray(R.array.antwoorden);
        text.setText(antwoorden[i]);
    }
    }

fragment_b.xml

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


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/textView"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true" />
</RelativeLayout>

PS: I'm a newbie :)

share|improve this question
    
share the code of the fragmentA – Younas Bangash yesterday
    
@Younas Bangash added :) – Glenn yesterday
up vote 0 down vote accepted

Remove the following from your layout XML:

<fragment
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:name="android.support.v4.app.DialogFragment"
    android:id="@+id/fragment2" />

You cannot use DialogFragment like that in layouts.

Also there's a typo in your method names that would cause similar problems later on:

public View onCreatewView

should be

@Override
public View onCreateView

in both fragments.

share|improve this answer
    
yes indeed there was the typo but that doesn't fix the error :s – Glenn yesterday
    
Edited to add another problem. – laalto yesterday
    
I couldn't remove the fragment because the main.class could not find the fragment.. I changed the DialogFragment to Listfragment and the activity starts.. The fragments are still loading so there's a problem there with the memory or so. and why can't I use DialogFragment in my layout? – Glenn yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.