gpt4 book ai didi

android - PreferenceFragmentCompat 在初始化时崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:36:08 54 4
gpt4 key购买 nike

我用 ViewPager 创建了一个应用程序。当我进行调试构建并在手机上进行测试时,一切正常。 (不是模拟器)但是当我构建一个发布 .apk 并安装它时,PreferenceFragmentCompat 的 addPreferencesFromResource(R.xml.preferences); 使应用程序崩溃。 PreferenceFragmentCompat - Android Developers

ApplicationSettingsFragment.java:

package hu.t_bond.homecontroller.Fragments;

import android.os.Bundle;
import android.support.v7.preference.PreferenceFragmentCompat;

import hu.t_bond.homecontroller.Launcher;
import hu.t_bond.homecontroller.R;

public class ApplicationSettingsFragment extends PreferenceFragmentCompat {

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

getPreferenceManager().setSharedPreferencesName(Launcher.SETTINGS_NAME);

addPreferencesFromResource(R.xml.preferences);
}

@Override
public void onCreatePreferences(Bundle bundle, String s)
{
}
}

res/xml/preferences.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<CheckBoxPreference
android:key="AutoUpdatesEnabled"
android:title="@string/auto_updates_enabled"
android:summary="@string/auto_updates_enabled_description"
android:defaultValue="true" />
</PreferenceScreen>

还有崩溃报告:

10-26 14:20:07.661 17763-17890/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: hu.t_bond.homecontroller, PID: 17763
android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
at android.support.v7.preference.p.a(PreferenceInflater.java:261)
at android.support.v7.preference.p.a(PreferenceInflater.java:280)
at android.support.v7.preference.p.b(PreferenceInflater.java:289)
at android.support.v7.preference.p.a(PreferenceInflater.java:161)
at android.support.v7.preference.p.a(PreferenceInflater.java:117)
at android.support.v7.preference.q.a(PreferenceManager.java:115)
at android.support.v7.preference.j.b(PreferenceFragmentCompat.java:366)
at hu.t_bond.homecontroller.b.a.d(ApplicationSettingsFragment.java:18)
at android.support.v4.b.o.h(Fragment.java:1942)
at android.support.v4.b.ac.a(FragmentManager.java:1040)
at android.support.v4.b.ac.b(FragmentManager.java:926)
at android.support.v4.b.o.c(Fragment.java:882)
at android.support.v4.b.an.b(FragmentStatePagerAdapter.java:152)
at android.support.v4.view.ViewPager.a(ViewPager.java:1104)
at android.support.v4.view.ViewPager.a(ViewPager.java:552)
at android.support.v4.view.ViewPager.a(ViewPager.java:514)
at android.support.v4.view.ViewPager.b(ViewPager.java:946)
at android.support.v4.view.dw.onChanged(ViewPager.java:2910)
at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
at android.support.v4.view.bo.c(PagerAdapter.java:276)
at hu.t_bond.homecontroller.w.c(Launcher.java:948)
at hu.t_bond.homecontroller.Launcher.a(Launcher.java:521)
at hu.t_bond.homecontroller.q.onClick(Launcher.java:663)
at android.view.View.performClick(View.java:4789)
at android.view.View$PerformClick.run(View.java:19881)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
at java.lang.Class.getConstructor(Class.java:531)
at java.lang.Class.getConstructor(Class.java:495)
at android.support.v7.preference.p.a(PreferenceInflater.java:248)
at android.support.v7.preference.p.a(PreferenceInflater.java:280) 
at android.support.v7.preference.p.b(PreferenceInflater.java:289) 
at android.support.v7.preference.p.a(PreferenceInflater.java:161) 
at android.support.v7.preference.p.a(PreferenceInflater.java:117) 
at android.support.v7.preference.q.a(PreferenceManager.java:115) 
at android.support.v7.preference.j.b(PreferenceFragmentCompat.java:366) 
at hu.t_bond.homecontroller.b.a.d(ApplicationSettingsFragment.java:18) 
at android.support.v4.b.o.h(Fragment.java:1942) 
at android.support.v4.b.ac.a(FragmentManager.java:1040) 
at android.support.v4.b.ac.b(FragmentManager.java:926) 
at android.support.v4.b.o.c(Fragment.java:882) 
at android.support.v4.b.an.b(FragmentStatePagerAdapter.java:152) 
at android.support.v4.view.ViewPager.a(ViewPager.java:1104) 
at android.support.v4.view.ViewPager.a(ViewPager.java:552) 
at android.support.v4.view.ViewPager.a(ViewPager.java:514) 
at android.support.v4.view.ViewPager.b(ViewPager.java:946) 
at android.support.v4.view.dw.onChanged(ViewPager.java:2910) 
at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37) 
at android.support.v4.view.bo.c(PagerAdapter.java:276) 
at hu.t_bond.homecontroller.w.c(Launcher.java:948) 
at hu.t_bond.homecontroller.Launcher.a(Launcher.java:521) 
at hu.t_bond.homecontroller.q.onClick(Launcher.java:663) 
at android.view.View.performClick(View.java:4789) 
at android.view.View$PerformClick.run(View.java:19881) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5292) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 

我正在使用最新的库:

compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:preference-v7:23.1.0'

有人可以告诉我我做错了什么吗?谢谢

最佳答案

OP 说他在构建 APK 文件时使用了 ProGuard。

作为this错误报告状态

Make sure your proguard configuration contains a line like this:

-keep public class * extends android.support.v7.preference.Preference

这可能是问题所在,但我不确定。

关于android - PreferenceFragmentCompat 在初始化时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33347085/

54 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com