0

I am doing an application using the PreferenceFragmentCompat when i call the PreferenceFragmentCompat i am getting the error like java.lang.NoClassDefFoundError i am getting the confused what to do i have tried and checked some google suggestion it is not solving the problem please help to solve it my Class which extends PreferenceFragmentCompat is as i am showing the code below

public class AutoAnswerPreferenceActivity extends PreferenceFragmentCompat implements OnSharedPreferenceChangeListener { 
    private AutoAnswerNotifier mNotifier;
    @Override
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preference);
        mNotifier = new AutoAnswerNotifier(getActivity()); 
        mNotifier.updateNotification();
        SharedPreferences sharedPreferences = getPreferenceManager().getSharedPreferences();
        sharedPreferences.registerOnSharedPreferenceChangeListener(this);
        /*PreferenceManager preferenceManager = getPreferenceManager();
        preferenceManager.getSharedPreferences()
                .registerOnSharedPreferenceChangeListener(this);*/


        }

    @Override
    public void onDestroy() { 
        getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
        super.onDestroy();
        }
    @Override 
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { 
        if (key.equals("enabled")) { 
            mNotifier.updateNotification();
            }  
        }


    @Override
    public void onCreatePreferences(Bundle arg0, String arg1) {
        // TODO Auto-generated method stub

    } 

and my fragment class is as shown below

public class AutoAnswarFragment extends Fragment {


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        // getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.container, new AutoAnswerPreferenceActivity()).commit();
        getActivity().getSupportFragmentManager().beginTransaction()
        .replace(R.id.container, new AutoAnswerPreferenceActivity ()).commit();

    }



    }

In Navigation Drawer i am calling the fragment to replace it as shown below

getSupportFragmentManager().beginTransaction()
            .replace(R.id.container, new AutoAnswarFragment(),null).commit(); 

the manifest file is as shown below

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".NavigationDrawerMainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <receiver
            android:name="com.koteswara.wise.autoanswer.AutoAnswerReceiver"
            android:enabled="true" >
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.koteswara.wise.autoanswer.AutoAnswerBootReceiver"
            android:enabled="true" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

        <service android:name="com.koteswara.wise.autoanswer.AutoAnswerIntentService" />

         <activity android:name="com.koteswara.wise.settings.GetCallerInfoActivity" 
                android:theme="@android:style/Theme.Dialog"
       ></activity>
    </application> 

please help to solve this i will be great full to you people. I am getting this error from the last one week

koteswara D K
  • 628
  • 2
  • 9
  • 19
  • `AutoAnswerPreferenceActivity` is a `PreferenceFragmentCompat` class. You can't treat it like an Activity, like listing it as one in the manifest. You should remove `Activity` from the class name to prevent confusion. – Mike M. Dec 07 '15 at 10:57
  • previously i am using it as a preference activity now i am changing it to preferenceFragment it is not removed if it is there or not it will not be problem as i tested with it – koteswara D K Dec 07 '15 at 11:01
  • Yeah, as long as you're not trying to start it as an Activity, it'll run. But if there's no need for it, why do you keep it in the manifest? That's just sloppy, and potentially confusing. Especially when you're asking other people to read your code. – Mike M. Dec 07 '15 at 11:03
  • i have commented it and working for the solution it is showing the same class not found error – koteswara D K Dec 07 '15 at 11:05

0 Answers0