MaterialDesignLibrary
MaterialDesignLibrary copied to clipboard
Error inflating class com.gc.materialdesign.views.CheckBox in API 10
Hi guys,
CheckBox works in API > 10, but in API 10 generates this crash.
android.view.InflateException: Binary XML file line #58: Error inflating class com.gc.materialdesign.views.CheckBox
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.afollestad.materialdialogs.MaterialDialog$Builder.customView(MaterialDialog.java:1313)
at com.resem.app.fragments.DetailDevelopmentAdvertFragment$2.onClick(DetailDevelopmentAdvertFragment.java:200)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at android.view.LayoutInflater.createView(LayoutInflater.java:505)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.afollestad.materialdialogs.MaterialDialog$Builder.customView(MaterialDialog.java:1313)
at com.resem.app.fragments.DetailDevelopmentAdvertFragment$2.onClick(DetailDevelopmentAdvertFragment.java:200)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.gc.materialdesign.views.CheckBox.invalidate(CheckBox.java:83)
at android.view.View.setBackgroundDrawable(View.java:7626)
at android.view.View.
Thanks.
+1 Surprised this hasn't been fixed, the checkbox is a little sketchy anyway, method names are slightly different for example (isCheck() or setOncheckListener()). For the moment we're probably better off sticking with the stock check box
Caused by: java.lang.NullPointerException at com.gc.materialdesign.views.CheckBox.invalidate(CheckBox.java:83)
just code check if it != null at CheckBox.java:83
/**
-
Created by lfd on 2015/10/28. */ public class FixCheckBox extends CheckBox{
public FixCheckBox(Context context, AttributeSet attrs) { super(context, attrs); }
@Override public void invalidate() { try { Object obj = null; Field field = CheckBox.class.getDeclaredField("checkView"); if(field!=null){ field.setAccessible(true); obj = field.get(this); } if(obj != null){ super.invalidate(); } } catch (Exception e) { e.printStackTrace(); } }
}
try it