Question

02-19 11:49:17.369: E/AndroidRuntime(4209): java.lang.NoClassDefFoundError: com.slidingmenus.fragments.HomeFragment
02-19 11:49:17.369: E/AndroidRuntime(4209):     at com.slidingmenus.MainActivity.displayCategoryView(MainActivity.java:242)
02-19 11:49:17.369: E/AndroidRuntime(4209):     at com.slidingmenus.MainActivity.onCreate(MainActivity.java:121)

Tried each and every steps suggested in stack overflow but they didn't help.

It works without an error in 4.0+ but in 2.3.x devices its giving java.lang.NoClassDefFoundError in

line 242: fragment = new HomeFragment();

My imports from fragments are:

import android.app.Fragment;
import android.app.FragmentManager;

and I'm using:

FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();

Here is my home fragment:

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

public class HomeFragment extends Fragment {        
   public HomeFragment(){}

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

           View rootView = inflater.inflate(R.layout.layout_main_fragment,container, false);

           return rootView;
    }
 }

Spent whole morning already trying to solve this. still no luck. Any help is highly appreciated.

Thanks

Was it helpful?

Solution

You should use Fragment from the support library.

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

You also need to use getSupportFragmentManager() and since you are using AppCompat your activity must extend ActionbarActivity.

 FragmentManager fragmentManager = getSupportFragmentManager();

Update:

ActionBarActivity is deprecated use AppCompatActivity from support library. Don't forget to update your support repository to the latest.

OTHER TIPS

Try this code Import:

import android.support.v4.app.Fragment;

And use

    Fragment fragment = new HomeFragment();
    android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(R.layout.layout_main_fragment, fragment).commit();

I faced the same issue and resolved it by import support library and used

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

Instead

import android.app.Fragment;
import android.app.FragmentManager;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top