NoClassDefFoundError:使用PreferenceFragmentCompat

时间:2015-12-07 10:50:01

标签: android performance android-fragments android-preferences android-preference-v14

当我调用PreferenceFragmentCompat时,我正在使用PreferenceFragmentCompat做一个应用程序我得到像java.lang.NoClassDefFoundError这样的错误我弄得很困惑我已经尝试过并检查了一些谷歌的建议它不解决问题请帮助解决它 扩展PreferenceFragmentCompat的我的类是在显示下面的代码

val c: Unit = "c"

我的片段类如下所示

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(); 

请帮助解决这个问题,我将很高兴为您服务。我从过去一周收到此错误

0 个答案:

没有答案