Zhen
Zhen

Reputation: 4283

Fragment inside Fragment error

I was changing a Activity to a Fragment to use inside a Scrollable Tab Activity. But I getting this exception I load this fragment:

FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #17: Error inflating class fragment
  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
  at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
  at com.zhensydow.demo.MainMenuFragment.onCreateView(MainMenuFragment.java:43)
  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
    ....

And the used (simplified) xml loaded is:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    ... >
  <fragment   <<---- LINE #17
    android:id="@+id/mlist"
    android:name="com.zhensydow.demo.MListFragment"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    tools:layout="@android:layout/mcontent" />

    <FrameLayout ... />
</LinearLayout>

The error is caused in this code:

public class MainMenuFragment extends Fragment implements
        MenuListFragment.Callbacks {

    // ...

    @Override
    public View onCreateView( LayoutInflater inflater, ViewGroup container, 
        Bundle savedInstanceState) 
    {
        super.onCreateView(inflater, container, savedInstanceState);

        LinearLayout ll = (LinearLayout) inflater.inflate(
                R.layout.activity_main_menu, container, false);

        return ll;
    }

    // ...

}

The error is on a fragment, I think it's caused because the old activity loaded two fragments inside him.

How can I solve it?

UPDATE: added full fragmen xml data

Upvotes: 0

Views: 344

Answers (2)

j__m
j__m

Reputation: 9625

I suspect your Fragment contains some code like this one, requiring your Activity to implement a callback interface, and your Activity does not implement that interface.

Upvotes: 1

j__m
j__m

Reputation: 9625

A fragment tag is required to have both a name and an id.

Upvotes: 0

Related Questions