当我调用 PreferenceFragmentCompat 时,我正在使用 PreferenceFragmentCompat 做一个应用程序我收到类似 java.lang.NoClassDefFoundError 的错误我很困惑我尝试过做什么并检查了一些谷歌建议它没有解决问题请帮助解决它是我扩展 PreferenceFragmentCompat 的类,因为我正在显示下面的代码
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
}
我的片段类如下所示
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();
}
}
在导航抽屉中,我调用片段来替换它,如下所示
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new AutoAnswarFragment(),null).commit();
清单文件如下所示
<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>
请帮助解决这个问题,我会很高兴为你们服务。我从过去一周收到此错误