开发者

Android preferences problem

开发者 https://www.devze.com 2023-02-05 04:26 出处:网络
I am following this tutorial: link text Preferences.java: public class Preferences extends PreferenceActivity{

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 savedInstan开发者_C百科ceState) {
        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:

Android preferences problem

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:

Android preferences problem

AndroidManifest.xml:

Android preferences problem

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.


Try removing this import, if you have it;

import java.util.prefs.Preferences;


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>


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号