Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 696
erdomester Avatar asked Feb 16 '26 17:02

erdomester


1 Answers

Try removing this import, if you have it;

import java.util.prefs.Preferences;
like image 55
SmT Avatar answered Feb 19 '26 06:02

SmT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!