每次尝试打开设置活动时,我的应用程序崩溃。在XML文件中没有RingtonePreference的话,一切都很好。堆栈跟踪:
07-25 05:30:39.244 3406-3406 / com.ovchinnikovm.android.vktop E / Android运行时:致命异常:主要 流程:com.ovchinnikovm.android.vktop,PID:3406 java.lang.RuntimeException:无法启动活动ComponentInfo {com.ovchinnikovm.android.vktop / com.ovchinnikovm.android.vktop.settings.SettingsActivity}:android.view.InflateException:二进制XML文件行#11:错误膨胀类(找不到)铃声偏好设置 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2560) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626) 在android.app.ActivityThread.-wrap11(ActivityThread.java) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1475) 在android.os.Handler.dispatchMessage(Handler.java:111) 在android.os.Looper.loop(Looper.java:207) 在android.app.ActivityThread.main(ActivityThread.java:5740) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:905) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766) 造成原因:android.view.InflateException:二进制XML文件第11行:错误夸大类(未找到) 在android.support.v7.preference.PreferenceInflater.createItemFromTag(PreferenceInflater.java:297) 在android.support.v7.preference.PreferenceInflater.rInflate(PreferenceInflater.java:354) 在android.support.v7.preference.PreferenceInflater.rInflate(PreferenceInflater.java:356) 在android.support.v7.preference.PreferenceInflater.inflate(PreferenceInflater.java:162) 在android.support.v7.preference.PreferenceInflater.inflate(PreferenceInflater.java:112) 在android.support.v7.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:137) 在android.support.v7.preference.PreferenceFragmentCompat.setPreferencesFromResource(PreferenceFragmentCompat.java:448) 在com.ovchinnikovm.android.vktop.settings.SettingsFragment.onCreatePreferences(SettingsFragment.java:21) 在android.support.v7.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:224) 在android.support.v4.app.Fragment.performCreate(Fragment.java:2331) 在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1386) 在android.support.v4.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1188) 在android.support.v4.app.FragmentTransition.calculateFragments(FragmentTransition.java:1071) 在android.support.v4.app.FragmentTransition.startTransitions(FragmentTransition.java:115) 在android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2380) 在android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338) 在android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245) 在android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3248) 在android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3200) 在android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:195) 在android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:597) 在android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177) 在android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1245) 在android.app.Activity.performStart(Activity.java:6581) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2523) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626) 在android.app.ActivityThread.-wrap11(ActivityThread.java) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1475) 在android.os.Handler.dispatchMessage(Handler.java:111) 在android.os.Looper.loop(Looper.java:207) 在android.app.ActivityThread.main(ActivityThread.java:5740) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:905) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766) 原因:java.lang.ClassNotFoundException:在路径:DexPathList [[zip文件“ /data/app/com.ovchinnikovm.android.vktop-2/base”中找不到类“ android.support.v7.preference.RingtonePreference” .apk”,zip文件“ /data/app/com.ovchinnikovm.android.vktop-2/split_lib_dependencies_apk.apk”、zip文件“ /data/app/com.ovchinnikovm.android.vktop-2/split_lib_slice_0_apk.apk”压缩文件“ /data/app/com.ovchinnikovm.android.vktop-2/split_lib_slice_1_apk.apk”,压缩文件“ /data/app/com.ovchinnikovm.android.vktop-2/split_lib_slice_2_apk.apk”,压缩文件“ / data / app / com.ovchinnikovm.android.vktop-2 / split_lib_slice_3_apk.apk”,zip文件“ /data/app/com.ovchin
Xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/notifications_title"
android:key="notification_title">
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="enable_notifications"
android:summary="@string/enable_notification_summary"
android:title="@string/notifications_title" />
<RingtonePreference
android:key="pref_tone"
android:title="@string/pref_tone"
android:showDefault="true"
android:ringtoneType="notification"
android:showSilent="true"/>
</PreferenceCategory>
</PreferenceScreen>
Java类:
public class SettingsActivity extends AppCompatActivity {
public static final String KEY_PREF_NOTIFICATION_SWITCH = "enable_notifications";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
}
片段:
public class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preferences, rootKey);
}
}
我在其中添加支持库的gradle的一部分:
implementation "com.android.support:appcompat-v7:27.1.1"
implementation 'com.android.support:support-v13:27.1.1'
implementation "com.android.support.constraint:constraint-layout:1.1.2"
implementation "com.android.support:recyclerview-v7:27.1.1"
implementation "com.android.support:cardview-v7:27.1.1"
implementation "com.android.support:design:27.1.1"
implementation 'com.android.support:preference-v7:27.1.1'
strings.xml文件中与SettingsActivity相关的部分:
<!-- Settings Screen -->
<string name="settings_label">Settings</string>
<string name="notifications_title">Notifications</string>
<string name="enable_notification_summary">Notifications report the end of the sorting when app is minimized</string>
<string name="pref_tone">Notification ringtone</string>