如何修复错误偏好Android

时间:2013-09-03 10:53:21

标签: android runtime-error preferences

调用屏幕首选项并关闭应用程序时出现应用程序错误。

我的MainActivity.java:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button config = (Button) findViewById(R.id.confg);
    config.setOnClickListener(new View.OnClickListener(){

        public void onClick(View v) {
            Intent settingsActivity = new Intent(getBaseContext(),PreferenciaActivity.class);
        }
    });
}

My PreferenciaActivity.java:

public class PreferenciaActivity  extends PreferenceActivity {

@Override
protected void onCreate(final Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    getFragmentManager().beginTransaction().replace(android.R.id.content , new PreferenciaFragment()).commit();
}

public static class PreferenciaFragment extends PreferenceFragment
{
    @Override
    public void onCreate(final Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.layout.preferencias);
    }
}

我的Preferencia.xml:

<?xml version="1.0" encoding="utf-8"?>

<PreferenceCategory android:title="liberador" >
    <CheckBoxPreference
            android:key="liberar"
            android:summary="Marque para liberar"
            android:title="Ativar" />

    <EditTextPreference
            android:dependency="liberador"
            android:key="codigo"
            android:summary="Informe o código"
            android:title="Código" />
</PreferenceCategory>

代码很简单,不知道错误在哪里。请帮忙!

1 个答案:

答案 0 :(得分:0)

您尚未开始活动

config.setOnClickListener(new View.OnClickListener(){

        public void onClick(View v) {
            Intent settingsActivity = new Intent(getBaseContext(),PreferenciaActivity.class);
            startActivity(settingsActivity)
        }
    });