Android:RuntimeException,带有库项目中的PreferenceScreen和自定义属性
我最近拆分了我的项目,创建了一个库项目和一个主项目。有了一个具有自定义属性的preferences屏幕,我从my preferences.xml中删除了具有自定义属性的首选项,将它们放入它们自己的xml文件中,将它们重新包含到preferences.xml文件中,并在主项目中重新定义了各个文件。该过程在对另一个问题的回答中有详细说明 该项目构建和运行正常。但是,每当我试图打开preferences屏幕时,就会出现RuntimeException。使用自定义属性删除prefs修复了这个问题,因此我将其追溯到那里。不幸的是,异常中没有有用的信息 attrs.xml存在于lib项目中 所有字符串都在lib项目中正确定义 如果我遗漏了什么,请告诉我。在我将我的项目拆分为lib和main之前,这些首选项工作得很好 非常感谢!Android:RuntimeException,带有库项目中的PreferenceScreen和自定义属性,android,preferences,custom-attributes,runtimeexception,Android,Preferences,Custom Attributes,Runtimeexception,我最近拆分了我的项目,创建了一个库项目和一个主项目。有了一个具有自定义属性的preferences屏幕,我从my preferences.xml中删除了具有自定义属性的首选项,将它们放入它们自己的xml文件中,将它们重新包含到preferences.xml文件中,并在主项目中重新定义了各个文件。该过程在对另一个问题的回答中有详细说明 该项目构建和运行正常。但是,每当我试图打开preferences屏幕时,就会出现RuntimeException。使用自定义属性删除prefs修复了这个问题,因此我
SeanPreferenceActivity.onCreate可以在内部抛出运行时异常,如果配置为这样做,IDE可能会捕获这些异常,但它们也会在内部捕获。例如,默认主题中缺少layout_width标记可能会导致异常 如果RuntimeException没有渗透回代码中,不要担心。如果是,您是否可以更新您的问题以包含异常消息和堆栈跟踪
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="numberpickerPref">
<attr name="maxValue" format="integer" />
<attr name="minValue" format="integer" />
</declare-styleable>
</resources>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/pref_VibrationSettingsTitle">
<CheckBoxPreference android:key="@string/pref_vibrateFlagKey"
android:title="@string/pref_VibrateTitle"
android:summary="@string/pref_VibrateSummary"
android:defaultValue="false" />
<include layout="@layout/pref_vibrate_on" />
<include layout="@layout/pref_vibrate_off" />
</PreferenceCategory>
</PreferenceScreen>
<?xml version="1.0" encoding="utf-8"?>
<!-- Stupid workaround because Android still has a bug where custom attributes in a library cause the executable project
problems when building:
https://stackoverflow.com/questions/4461407/help-with-a-custom-view-attributes-inside-a-android-library-project -->
<com.me.numberpicker.NumberPickerPreference
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:my="http://schemas.android.com/apk/res/com.me.myapp.lib"
android:key="@string/pref_vibrateOffPeriodKey"
android:title="@string/pref_VibrateOffTitle"
android:summary="@string/pref_VibrateOffSummary"
my:maxValue="@string/MaxVibratorOffPeriodInS"
my:minValue="@string/MinVibratorOffPeriodInS"
android:defaultValue="@string/DefaultVibratorOffPeriodInS" />
public class MegalarmPreferencesActivity extends PreferenceActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}