erdomester
erdomester

Reputation: 11829

Android preferences problem

I am following this tutorial: 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 application starts, and i click the prefButton, an error occures: "The application PreferencesTutorial (process PreferencesTutorial.com.examples) has stopped unexpectedly. Please try again"

I haven't found any mistakes in the code. I would also like to show my filestructure if that helps: alt text

AndroidManifest.xml: alt text

What is wrong with the code?

Even if i add (where the cursor is)

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

i still get the error.

Upvotes: 3

Views: 2372

Answers (4)

SmT
SmT

Reputation: 335

Try removing this import, if you have it;

import java.util.prefs.Preferences;

Upvotes: 1

Ashish
Ashish

Reputation: 259

You have to mention this in your androidManifest.xml file

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

        </intent-filter>  
</activity>

Upvotes: 0

Jay Dee
Jay Dee

Reputation: 364

Is the error raised in the OnClick in PreferencesTutorial Class or onCreate in the preferences Class? Stick a couple of Log.d("Debug","%ID") in various locations and see which one doesn't get called.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007554

You probably do not have Preferences defined in your manifest.

However, as others have indicated, use adb logcat, DDMS, or the DDMS perspective in Eclipse to examine LogCat and see the stack trace associated with your crash.

Upvotes: 0

Related Questions