I have a custom preference, which extends from android.support.v7.preference.EditTextPreference
. Everything works fine, except when I call
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
which causes the app to crash with Caused by: java.lang.ClassCastException: com.my.project.EditTextPreferenceWithSummary cannot be cast to android.preference.Preference
on the above line.
My custom class is a simple extension of android.support.v7.preference.EditTextPreference
:
public class EditTextPreferenceWithSummary extends EditTextPreference
So how can I call setDefaultValues()
and avoid the ClassCastException
?
For me, the problem was that the wrong version of PerformanceManager was imported into my classes. The import must be updated to reference the v7.performance.PerformanceManager.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.