Note that there are some explanatory texts on larger screens.

plurals
  1. PODialogPreference force close
    text
    copied!<p>For a school project, I'm building an application using <code>PreferenceScreen</code>s as a framework.<br> I've created 2 new classes to suit my needs: <code>SeekBarDialogPreference</code> (designed to handle volumes and brightness) and <code>DigitalPreference</code> (for everything else).</p> <pre><code>class SeekBarDialogPreference extends DialogPreference { static HashMap&lt;String, Integer&gt; maxValues = new HashMap&lt;String, Integer&gt;(6); AudioManager am = (AudioManager) APP.getContext().getSystemService(Context.AUDIO_SERVICE); View views = new View(APP.getContext()); SeekBar sb; CheckBox cb; @Override protected void onBindDialogView(View view) { sb = (SeekBar) views.findViewById(R.id.seekbar); cb = (CheckBox) views.findViewById(R.id.unchanged_check); sb.setMax(maxValues.get(this.getKey())); super.onBindDialogView(view); } @Override protected void onDialogClosed(boolean positiveresult) { super.onDialogClosed(positiveresult); if (positiveresult) { Editor editor = getEditor(); editor.putInt(this.getKey(), cb.isChecked() ? -1 : sb.getProgress()); editor.commit(); } } void show() { onClick(); } } </code></pre> <p>and the DigitalPreference</p> <pre><code>public class DigitalPreference extends ListPreference{ void show(){ onClick(); } </code></pre> <p>Here's the unifying TopPage, which is the main page</p> <pre><code>public class TopPage extends PreferenceActivity { @Override public void onCreate(Bundle allthethings) { super.onCreate(allthethings); Map&lt;String, ?&gt; shareprefs = PreferenceManager.getDefaultSharedPreferences(this).getAll(); addPreferencesFromResource(R.xml.prefs); } @Override public void onStart() { getPrefs(); } private SeekBarDialogPreference makeSeekBar(Preference pref) { return (SeekBarDialogPreference) findPreference(pref.getKey()); } private DigitalPreference makeDigital(Preference pref) { return (DigitalPreference) findPreference(pref.getKey()); } private void setClickListener(Preference preference, final boolean isSeekBar) { preference.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference pref) { if (isSeekBar) { makeSeekBarDialogPreference(pref).show(); } else { makeDigitalPreference(pref).show(); } return true; } }); } public void getPrefs() { SeekBarDialogPreference Ringvolume_preference = (SeekBarDialogPreference) findPreference("Ringvolume_preference"); setClickListener(Ringvolume_Preference, true); //Instantiated each Preference and attached a ClickListener to each } </code></pre> <p>I have all of the preferences declared in res/xml/prefs.xml. Now whenever I run the app, I get an immediate force close. I suspect there's something wrong with my Manifest:</p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.gobernador" android:versionCode="1" android:versionName="0.1"&gt; &lt;uses-sdk android:minSdkVersion="5" android:targetSdkVersion="10"/&gt; &lt;application android:label="@string/app_name" android:name="APP"&gt; &lt;activity android:name=".TopPage" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>I've referenced <a href="https://stackoverflow.com/questions/5516022/android-launch-a-custom-preference-from-a-preferenceactivity">Android: launch a custom Preference from a PreferenceActivity</a>, among other stackoverflow questions, but I haven't been able to work out the problem.</p> <p>If someone could shepherd me in the right direction, you would be getting me out of a huge rut. Thanks!</p> <p>EDIT: After swimming through the logcat, I found an exception thrown in my prefs.xml file.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="Settings"&gt; &lt;PreferenceScreen android:title="Volumes" android:summary="Ring, Notification, System, etc."&gt; &lt;com.gobernador.SeekBarDialogPreference android:key="Ringvolume_preference" android:title="Ring Volume" android:summary="" android:dialogLayout="@layout/seekbar_layout"/&gt; &lt;com.gobernador.SeekBarDialogPreference android:key="Notifyvolume_preference" android:title="Notification Volume" android:summary="" android:dialogLayout="@layout/seekbar_layout"/&gt; ... and so on </code></pre> <p>where it tries to access the <code>SeekBarDialogPreference</code>. Why isn't it working?</p> <p>EDIT: The Exception being thrown is a <code>NoSuchMethodException: SeekBarDialogPreference(Context,AttributeSet)</code>. I defined that method, what did I miss?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload