Reputation: 11829
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:
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:
AndroidManifest.xml:
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
Reputation: 335
Try removing this import, if you have it;
import java.util.prefs.Preferences;
Upvotes: 1
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
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
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