Android preference issue

I follow this guide: link text

Preferences.java:

public class Preferences extends PreferenceActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
}

}

PreferencesTutorial.java:

public class PreferencesTutorial extends Activity{

@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button prefBtn = (Button) findViewById(R.id.prefButton);
        prefBtn.setOnClickListener(new OnClickListener() {

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

}

preferences.xml: alt text

When the application starts, and I press the prefButton button, an error occurs: "The PreferencesTutorial application (PreferencesTutorial.com.examples process) has stopped unexpectedly. Please try again"

I did not find errors in the code. I would also like to show my philology if this helps: alt text

AndroidManifest.xml: alt text

What is wrong with the code?

Even if I add (where is the cursor)

<activity
        android:name=".Preferences"
        android:label="@string/set_preferences">
    </activity>

I am still getting an error.

+3
source share
4 answers

You should mention this in the androidManifest.xml file

<activity
        android:name=".Preferences"
        android:label="@string/set_preferences">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT"/>

        </intent-filter>  
</activity>
0
source

Try to remove this import, if you have one;

import java.util.prefs.Preferences;
+1

You probably don't have Preferencesone defined in your manifest.

However, as others have pointed out, use adb logcatDDMS or the DDMS perspective in Eclipse to check the LogCat and view the stack trace associated with your failure.

0
source

Does an error occur in the OnClick class in the PreferencesTutorial or onCreate in the preference class? Attach a pair of Log.d ("Debug", "% ID") in different places and see which one is not called.

0
source

Source: https://habr.com/ru/post/1786272/


All Articles