SimonVT / android-menudrawer

*DEPRECATED* A slide-out menu implementation, which allows users to navigate between views in your app.
http://simonvt.github.com/android-menudrawer/
Apache License 2.0
2.59k stars 1.11k forks source link

Issue affecting Android v2.3.5 Only #231

Closed mardawi closed 10 years ago

mardawi commented 10 years ago

An uncaught exception with following stack trace have occurred over 1,600 in the last month for an app using menudrawer. It only happens on 2.3.5 on Samsung S2 devices (such as GT-I9100 or GT-I9100T or GT-I9001). Any idea what is going on? Any suggestion for a workaround?

java.lang.NullPointerException android.widget.AbsListView.contentFits(AbsListView.java:775) android.widget.AbsListView.draw(AbsListView.java:3037) android.view.ViewGroup.drawChild(ViewGroup.java:1646) android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) android.view.View.draw(View.java:6936) android.view.View.buildDrawingCache(View.java:6695) android.view.View.getDrawingCache(View.java:6481) android.view.ViewGroup.drawChild(ViewGroup.java:1571) android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) android.view.ViewGroup.drawChild(ViewGroup.java:1644) android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) net.simonvt.menudrawer.BuildLayerFrameLayout.dispatchDraw(SourceFile:77) android.view.View.draw(View.java:6936) android.widget.FrameLayout.draw(FrameLayout.java:357) android.view.ViewGroup.drawChild(ViewGroup.java:1646) android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) net.simonvt.menudrawer.MenuDrawer.dispatchDraw(SourceFile:671) android.view.View.draw(View.java:6936) android.view.ViewGroup.drawChild(ViewGroup.java:1646) android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) android.view.ViewGroup.drawChild(ViewGroup.java:1644) android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) android.view.ViewGroup.drawChild(ViewGroup.java:1644) android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) android.view.ViewGroup.drawChild(ViewGroup.java:1644) android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) android.view.View.draw(View.java:6936) android.widget.FrameLayout.draw(FrameLayout.java:357) com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1917) android.view.ViewRoot.draw(ViewRoot.java:1530) android.view.ViewRoot.performTraversals(ViewRoot.java:1266) android.view.ViewRoot.handleMessage(ViewRoot.java:1868) android.os.Handler.dispatchMessage(Handler.java:99) android.os.Looper.loop(Looper.java:130) android.app.ActivityThread.main(ActivityThread.java:3691) java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke(Method.java:507) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) dalvik.system.NativeStart.main(Native Method)

SimonVT commented 10 years ago

Not an issue with this library, the crash is in AbsListView.

mardawi commented 10 years ago

The following patch fixes the issue. Tested on over 65k devices :)

Index: menudrawer/src/net/simonvt/menudrawer/BuildLayerFrameLayout.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- menudrawer/src/net/simonvt/menudrawer/BuildLayerFrameLayout.java    (revision 1260f2f6d50d3b572ebfa98e93a0b4f8258371de)
+++ menudrawer/src/net/simonvt/menudrawer/BuildLayerFrameLayout.java    (revision )
@@ -3,6 +3,7 @@
 import android.content.Context;
 import android.graphics.Canvas;
 import android.util.AttributeSet;
+import android.util.Log;
 import android.widget.FrameLayout;

 /**
@@ -12,6 +13,7 @@
  */
 class BuildLayerFrameLayout extends FrameLayout {

+    private static final String TAG = BuildLayerFrameLayout.class.getSimpleName();
     private boolean mChanged;

     private boolean mHardwareLayersEnabled = true;
@@ -74,7 +76,12 @@

     @Override
     protected void dispatchDraw(Canvas canvas) {
+        try {
+            if (getChildCount() > 0)
-        super.dispatchDraw(canvas);
+                super.dispatchDraw(canvas);
+        } catch (NullPointerException e) {
+            Log.e(TAG, "Error on dispatchDraw BuildLayerFrameLayout : " + e);
+        }

         if (mChanged && MenuDrawer.USE_TRANSLATIONS) {
             post(new Runnable() {