theJava
theJava

Reputation: 15034

No view found for id 0x7f070000 for fragment

I get this error when I try to load my Fragment in my ActionBar.

Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f070000 for fragment HomeFragment{4100e030 #0 id=0x7f070000}

public class HomeFragment extends Fragment {    
    @Override
    public View onCreateView(LayoutInflater inflater, 
                  ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.home, container, false);
    }    
}

The below is my mainActivity

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

        final ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        Tab homeTab = actionBar.newTab();
        homeTab.setText("Home");
        homeTab.setIcon(R.drawable.home);

        Fragment homeFragment = new HomeFragment();

        homeTab.setTabListener(new MyTabsListener(homeFragment));

        actionBar.addTab(homeTab);

    }

MainActivity XML

<RelativeLayout 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" >

</RelativeLayout>

Upvotes: 0

Views: 1489

Answers (1)

dmnlk
dmnlk

Reputation: 3045

you should input viewGroup resource ID which is ContentView in ParentActivity.

does you Parent Activity have LinearLayout or Relativelayout as ContentView.

if yes, you should choose it in inflate method's augument.

Upvotes: 1

Related Questions