ユーザーが CheckBox 以外のものをクリックしたときに がクリックされないようにするカスタムCheckBoxPreference
クラスを作成しました。CheckBoxPreference
昨日は出発前に完全に機能していましたが、奇妙な理由で今日は機能しません。アプリがクラッシュし、次のエラーが発生します。
致命的な例外: メイン プロセス: ca.qc.gouv.stat.kth、PID: 19543 java.lang.RuntimeException: アクティビティ ComponentInfo{ca.qc.gouv.stat.kth/ca.qc.gouv.stat.kth を開始できません.AppPreferenceActivity}: android.view.InflateException: バイナリ XML ファイルの行 #24: クラス ca.qc.gouv.stat.kth.CustomCheckBoxPreference の膨張エラー
コードの次の行でクラッシュします。 addPreferencesFromResource(R.xml.preferences);
今朝のメイン アクティビティに Log.i 行を追加した以外は、プロジェクトに何も変更を加えていないことはほぼ確実です。この行にコメントしてみました。プロジェクトのキャッシュを消去します。Gradle プロジェクトを更新します。Google 検索では、エラーの膨張クラスに関する多くの結果が返されました。質問があるのと同じくらい多くの解決策があると思います。非常に一般的なエラーのようです。
ファイル内のカスタムを通常のカスタムCheckBoxPreference
に置き換えると、機能します。preferences.xml
カスタムのクラスにブレークポイントを配置しても、ブレークポイントはCheckBoxPreference
壊れません。クラスのコードは決して実行されないようです。昨日は機能していたと100%確信しているので、完全に迷っています。
CheckBoxPreference
これが私が行ったカスタムクラスです:
package ca.qc.gouv.stat.kth;
import android.content.Context;
import android.preference.CheckBoxPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
public class CustomCheckBoxPreference extends CheckBoxPreference {
private CheckBoxPreference clickedCheckBoxPreference;
CustomCheckBoxPreference(Context context) {
super(context);
}
CustomCheckBoxPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
CustomCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
CustomCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
clickedCheckBoxPreference = this;
CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
TextView title = (TextView) view.findViewById(android.R.id.title);
title.setSingleLine(false);
view.setOnClickListener(null);
title.setOnClickListener(null);
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckBox clickedCheckBox = (CheckBox) v;
if (clickedCheckBox.isChecked()) {
clickedCheckBoxPreference.setChecked(true);
} else {
clickedCheckBoxPreference.setChecked(false);
}
}
});
}
}
preferences.xml
ファイルは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sbp="http://schemas.android.com/apk/res/ca.qc.gouv.stat.kth">
<EditTextPreference
android:title="@string/url_title"
android:key="url"
android:defaultValue="@string/app_url"
/>
<EditTextPreference
android:title="@string/pwd_title"
android:key="pwd"
android:defaultValue="@string/app_pwd"
/>
<ListPreference
android:title="@string/orientation_title"
android:key="orientation"
android:entries="@array/orientation_display"
android:entryValues="@array/orientation_values"
android:defaultValue="@string/app_orientation"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/progress_title"
android:key="progress"
android:defaultValue="@string/app_progress"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/js_title"
android:key="js"
android:defaultValue="@string/app_js"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/tts_title"
android:key="tts"
android:defaultValue="@string/app_tts"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/clear_cache_title"
android:key="clear_cache"
android:defaultValue="@string/app_clear_cache"
android:disableDependentsState="true"
/>
<ListPreference
android:title="@string/cache_mode_title"
android:key="cache_mode"
android:entries="@array/cache_mode_display"
android:entryValues="@array/cache_mode_values"
android:defaultValue="@string/app_cache_mode"
android:dependency="clear_cache"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/clear_history_title"
android:key="clear_history"
android:defaultValue="@string/app_clear_history"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/clear_form_title"
android:key="clear_form"
android:defaultValue="@string/app_clear_form"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/keep_alive_title"
android:key="keep_alive"
android:defaultValue="@string/app_keep_alive"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/viewport_title"
android:key="viewport"
android:defaultValue="@string/app_viewport"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/fit_title"
android:key="fit"
android:defaultValue="@string/app_fit"
android:dependency="viewport"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/zoom_support_title"
android:key="zoom_support"
android:defaultValue="@string/app_zoom_support"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/zoom_controls_title"
android:key="zoom_controls"
android:defaultValue="@string/app_zoom_controls"
android:dependency="zoom_support"
/>
<ca.qc.gouv.stat.kth.SeekBarPreference
android:key="zoom_default"
android:title="@string/zoom_default_title"
android:defaultValue="@string/app_zoom_default"
sbp:maxValue="100"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/error_back_btn_title"
android:key="error_back_btn"
android:defaultValue="@string/app_error_back_btn"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/error_home_btn_title"
android:key="error_home_btn"
android:defaultValue="@string/app_error_home_btn"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/restrict_host_title"
android:key="restrict_host"
android:defaultValue="@string/app_restrict_host"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/debug_info_title"
android:key="debug_info"
android:defaultValue="@string/app_debug_info"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/autocomplete_title"
android:key="autocomplete"
android:defaultValue="@string/app_autocomplete"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/adjust_height_title"
android:key="adjust_height"
android:defaultValue="@string/app_adjust_height"
/>
<ca.qc.gouv.stat.kth.SeekBarPreference
android:key="adjust_tolerance"
android:title="@string/adjust_tolerance_title"
android:defaultValue="@string/app_adjust_tolerance"
android:dependency="adjust_height"
sbp:maxValue="100"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/long_click_title"
android:key="long_click"
android:defaultValue="@string/app_long_click"
/>
<ca.qc.gouv.stat.kth.SeekBarPreference
android:key="settings_delay"
android:title="@string/settings_delay_title"
android:defaultValue="@string/app_settings_delay"
sbp:maxValue="5"
/>
<ca.qc.gouv.stat.kth.SeekBarPreference
android:key="settings_nb_touch"
android:title="@string/settings_nb_touch_title"
android:defaultValue="@string/app_settings_nb_touch"
sbp:maxValue="10"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/file_access_title"
android:key="file_access"
android:defaultValue="@string/app_file_access"
/>
<ListPreference
android:title="@string/js_file_access_title"
android:key="js_file_access"
android:entries="@array/js_file_access_display"
android:entryValues="@array/js_file_access_values"
android:defaultValue="@string/app_js_file_access"
/>
<ca.qc.gouv.stat.kth.CustomCheckBoxPreference
android:title="@string/content_url_access_title"
android:key="content_url_access"
android:defaultValue="@string/app_content_url_access"
/>
<ListPreference
android:title="@string/mixed_content_title"
android:key="mixed_content"
android:entries="@array/mixed_content_display"
android:entryValues="@array/mixed_content_values"
android:defaultValue="@string/app_mixed_content"
/>
<Preference
android:title="@string/exit_btn_lbl"
android:key="exit"
/>
</PreferenceScreen>
ターゲット API 26、最小 API 21;