我遇到了这个崩溃,支持库23.0.1
在显示Dialog Fragment时会发生这种情况。
它使用android.support.v4.app.DialogFragment
和android.support.v7.app.AppCompatDialogFragment
其他人正在经历这个?
它总是发生在发布编译(启用了Proguard),并且仅在某些情况下使用调试编译。
我正在报告两个片段类的崩溃堆栈。
android.support.v4.app.DialogFragment 的堆栈:
android.view.InflateException: Binary XML file line #115: Error inflating class Button
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
at com.android.internal.app.AlertController.installContent(AlertController.java:235)
at android.app.AlertDialog.onCreate(AlertDialog.java:356)
at android.app.Dialog.dispatchOnCreate(Dialog.java:373)
at android.app.Dialog.show(Dialog.java:274)
at android.support.v4.app.DialogFragment.onStart(SourceFile:406)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1060)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1207)
at android.support.v4.app.BackStackRecord.run(SourceFile:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:1572)
at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:493)
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:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.o.a()' on a null object reference
at android.support.v7.widget.AppCompatButton.setBackgroundDrawable(SourceFile:85)
at android.view.View.setBackground(View.java:16226)
at android.view.View.(View.java:4103)
at android.widget.TextView.(TextView.java:637)
at android.widget.Button.(Button.java:111)
at android.widget.Button.(Button.java:107)
at android.support.v7.widget.AppCompatButton.(SourceFile:64)
at android.support.v7.widget.AppCompatButton.(SourceFile:60)
at android.support.v7.internal.app.AppCompatViewInflater.createView(SourceFile:101)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:966)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
at com.android.internal.app.AlertController.installContent(AlertController.java:235)
at android.app.AlertDialog.onCreate(AlertDialog.java:356)
at android.app.Dialog.dispatchOnCreate(Dialog.java:373)
at android.app.Dialog.show(Dialog.java:274)
at android.support.v4.app.DialogFragment.onStart(SourceFile:406)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1060)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1207)
at android.support.v4.app.BackStackRecord.run(SourceFile:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:1572)
at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:493)
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:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
android.support.v7.app.AppCompatDialogFragment 的堆栈:
android.view.InflateException: Binary XML file line #29: Error inflating class Button
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at eu.baroncelli.oraritrenitalia.mainactivity.AlertDialogFragment.onCreateView(SourceFile:62)
at android.support.v4.app.Fragment.performCreateView(SourceFile:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1026)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1207)
at android.support.v4.app.BackStackRecord.run(SourceFile:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:1572)
at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:493)
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:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.o.a()' on a null object reference
at android.support.v7.widget.AppCompatButton.setBackgroundDrawable(SourceFile:85)
at android.view.View.setBackground(View.java:16226)
at android.view.View.(View.java:4103)
at android.widget.TextView.(TextView.java:637)
at android.widget.Button.(Button.java:111)
at android.widget.Button.(Button.java:107)
at android.support.v7.widget.AppCompatButton.(SourceFile:64)
at android.support.v7.widget.AppCompatButton.(SourceFile:60)
at android.support.v7.internal.app.AppCompatViewInflater.createView(SourceFile:101)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:966)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at eu.baroncelli.oraritrenitalia.mainactivity.AlertDialogFragment.onCreateView(SourceFile:62)
at android.support.v4.app.Fragment.performCreateView(SourceFile:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1026)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1207)
at android.support.v4.app.BackStackRecord.run(SourceFile:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:1572)
at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:493)
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:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
答案 0 :(得分:12)
根据this,如果您使用appcompat-v7,则您的proguard设置应包含以下规则:
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
public <init>(android.content.Context);
}
使用SearchView和我想象的其他东西时,这也可以避免麻烦。