viezel / NappDrawer

A side drawer navigation container view controller for Appcelerator Titanium.
MIT License
248 stars 128 forks source link

Hiding actionbar crashes app randomly with SDK 4.X.X #161

Open arifje opened 9 years ago

arifje commented 9 years ago

I am hiding the actionBar after the nappdrawer window has opened, but with SDK 4.X.X (tried 4.0.0.GA and 4.0.1, 4.1.0) it crashes randomly.

Hiding the actionbar (works on 3.5.1.GA)

mainAppWindow.addEventListener('open', onDrawerOpen);
function onDrawerOpen(evt) {

  this.removeEventListener('open', onDrawerOpen);

  var actionBar = this.getActivity().getActionBar();

  if(actionBar) {
    actionBar.hide();               
  }
}

Now, with the latest 4.X SDK, it crashes randomly, and generating the following error:

[INFO] :   [appwindow.js] main drawer window has opened
[WARN] :   W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setId(int)' on a null object reference
[WARN] :   W/System.err:    at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:346)
[WARN] :   W/System.err:    at android.support.v7.app.ActionBarActivityDelegateBase.createSupportActionBar(ActionBarActivityDelegateBase.java:155)
[WARN] :   W/System.err:    at android.support.v7.app.ActionBarActivityDelegate.getSupportActionBar(ActionBarActivityDelegate.java:123)
[WARN] :   W/System.err:    at android.support.v7.app.ActionBarActivity.getSupportActionBar(ActionBarActivity.java:73)
[WARN] :   W/System.err:    at org.appcelerator.titanium.proxy.ActionBarProxy.<init>(ActionBarProxy.java:57)
[WARN] :   W/System.err:    at org.appcelerator.titanium.proxy.ActivityProxy.getActionBar(ActivityProxy.java:257)
[WARN] :   W/System.err:    at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[WARN] :   W/System.err:    at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
[WARN] :   W/System.err:    at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:908)
[WARN] :   W/System.err:    at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1131)
[WARN] :   W/System.err:    at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:347)
[WARN] :   W/System.err:    at org.appcelerator.titanium.proxy.TiWindowProxy.handleMessage(TiWindowProxy.java:101)
[WARN] :   W/System.err:    at dk.napp.drawer.DrawerProxy.handleMessage(DrawerProxy.java:101)
[WARN] :   W/System.err:    at android.os.Handler.dispatchMessage(Handler.java:98)
[WARN] :   W/System.err:    at android.os.Looper.loop(Looper.java:135)
[WARN] :   W/System.err:    at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
[ERROR] :  TiExceptionHandler: (main) [99,519] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,519] - In alloy/controllers/appWindow.js:14,44
[ERROR] :  TiExceptionHandler: (main) [0,519] - Message: Uncaught Error: Attempt to invoke virtual method 'void android.view.View.setId(int)' on a null object reference
[ERROR] :  TiExceptionHandler: (main) [0,519] - Source:         var actionBar = this.getActivity().getActionBar();
[ERROR] :  V8Exception: Exception

Image

When I don't hide the actionbar it doesn't crash.

arifje commented 9 years ago

After some testing I think I found the cause. It's caused by the orientationModes parameter.

My code for initialising the drawer window:

var orientations = [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT];

// alloy landscape for tablets
if(Alloy.Globals.isTablet || Alloy.Globals.isPhablet) {
    orientations = [
        Ti.UI.PORTRAIT, 
        Ti.UI.UPSIDE_PORTRAIT,
        Ti.UI.LANDSCAPE_LEFT,
        Ti.UI.LANDSCAPE_RIGHT
    ];
}

var mainAppWindow = NappDrawerModule.createDrawer({
    opacity: 1,
    fullscreen:false, 
    leftWindow: tmpLeft,
    exitOnClose: true,
    centerWindow: tmpCenter,
    rightWindow: rightWindow,
    fading: 0.2, // 0-1
    parallaxAmount: 0.2, //0-1
    shadowWidth:"5dp", 
    leftDrawerWidth: drawerWidth,
    rightDrawerWidth: drawerWidth,
    animationMode: NappDrawerModule.ANIMATION_NONE,
    closeDrawerGestureMode: NappDrawerModule.CLOSE_MODE_MARGIN,
    openDrawerGestureMode: NappDrawerModule.OPEN_MODE_ALL,
    orientationModes: orientations 
});

This causes the app to crash randomly. If it not happens the first time the app starts, it happens after restarting the app a few times. When I remove the parameter the drawer works perfectly.

Logcat output:

I/ActivityManager(  548): START u0 {cmp=test.project.com/org.appcelerator.titanium.TiActivity (has extras)} from pid 1852
W/InputMethodManagerService(  548): Focus gain on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@52a04014 (uid=10059 pid=1852)
D/dalvikvm( 1852): GC_FOR_ALLOC freed 774K, 6% free 15164K/16080K, paused 3ms, total 3ms
D/TiAPI   ( 1852):  windowDidClose main app window!
I/TiAPI   ( 1852):  [appwindow.js] main drawer window has opened
I/dalvikvm( 1852): Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
W/dalvikvm( 1852): VFY: unable to resolve virtual method 11985: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
D/dalvikvm( 1852): VFY: replacing opcode 0x6f at 0x0000
I/dalvikvm( 1852): Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
W/dalvikvm( 1852): VFY: unable to resolve virtual method 11991: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
D/dalvikvm( 1852): VFY: replacing opcode 0x6f at 0x0000
I/dalvikvm( 1852): Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLa
yout.setHideOnContentScrollEnabled
W/dalvikvm( 1852): VFY: unable to resolve virtual method 9550: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
D/dalvikvm( 1852): VFY: replacing opcode 0x6e at 0x000e
I/dalvikvm( 1852): Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurat
ions
W/dalvikvm( 1852): VFY: unable to resolve virtual method 542: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
D/dalvikvm( 1852): VFY: replacing opcode 0x6e at 0x0002
I/dalvikvm( 1852): Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
W/dalvikvm( 1852): VFY: unable to resolve virtual method 564: Landroid/content/res/TypedArray;.getType (I)I
D/dalvikvm( 1852): VFY: replacing opcode 0x6e at 0x0002
D/AndroidRuntime( 1852): Shutting down VM
W/dalvikvm( 1852): threadid=1: thread exiting with uncaught exception (group=0xa4c8db20)
E/TiApplication( 1852): (main) [296,296] Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to start activity ComponentInfo{test.project.com/org.appcelerator.titani
um.TiActivity}: java.lang.NullPointerException; Titanium 4.1.0,2015/05/27 22:13,17dc875
E/TiApplication( 1852): java.lang.RuntimeException: Unable to start activity ComponentInfo{test.project.com/org.appcelerator.titanium.TiActivity}: java.lang.NullPointerException
E/TiApplication( 1852):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
E/TiApplication( 1852):         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
E/TiApplication( 1852):         at android.app.ActivityThread.access$800(ActivityThread.java:135)
E/TiApplication( 1852):         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
E/TiApplication( 1852):         at android.os.Handler.dispatchMessage(Handler.java:102)
E/TiApplication( 1852):         at android.os.Looper.loop(Looper.java:136)
E/TiApplication( 1852):         at android.app.ActivityThread.main(ActivityThread.java:5001)
E/TiApplication( 1852):         at java.lang.reflect.Method.invokeNative(Native Method)
E/TiApplication( 1852):         at java.lang.reflect.Method.invoke(Method.java:515)
E/TiApplication( 1852):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/TiApplication( 1852):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
E/TiApplication( 1852):         at dalvik.system.NativeStart.main(Native Method)
E/TiApplication( 1852): Caused by: java.lang.NullPointerException
E/TiApplication( 1852):         at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:344)
E/TiApplication( 1852):         at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:216)
E/TiApplication( 1852):         at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:107)
E/TiApplication( 1852):         at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:555)
E/TiApplication( 1852):         at org.appcelerator.titanium.TiActivity.onCreate(TiActivity.java:18)
E/TiApplication( 1852):         at android.app.Activity.performCreate(Activity.java:5231)
E/TiApplication( 1852):         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/TiApplication( 1852):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
E/TiApplication( 1852):         ... 11 more
E/AndroidRuntime( 1852): FATAL EXCEPTION: main
E/AndroidRuntime( 1852): Process: test.project.com, PID: 1852
E/AndroidRuntime( 1852): java.lang.RuntimeException: Unable to start activity ComponentInfo{test.project.com/org.appcelerator.titanium.TiActivity}: java.lang.NullPointerException
E/AndroidRuntime( 1852):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
E/AndroidRuntime( 1852):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
E/AndroidRuntime( 1852):        at android.app.ActivityThread.access$800(ActivityThread.java:135)
E/AndroidRuntime( 1852):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
E/AndroidRuntime( 1852):        at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 1852):        at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 1852):        at android.app.ActivityThread.main(ActivityThread.java:5001)
E/AndroidRuntime( 1852):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1852):        at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 1852):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/AndroidRuntime( 1852):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
E/AndroidRuntime( 1852):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1852): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 1852):        at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:344)
E/AndroidRuntime( 1852):        at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:216)
E/AndroidRuntime( 1852):        at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:107)
E/AndroidRuntime( 1852):        at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:555)
E/AndroidRuntime( 1852):        at org.appcelerator.titanium.TiActivity.onCreate(TiActivity.java:18)
E/AndroidRuntime( 1852):        at android.app.Activity.performCreate(Activity.java:5231)
E/AndroidRuntime( 1852):        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/AndroidRuntime( 1852):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
E/AndroidRuntime( 1852):        ... 11 more
W/ActivityManager(  548):   Force finishing activity test.project.com/org.appcelerator.titanium.TiActivity
W/ActivityManager(  548):   Force finishing activity test.project.com/.TestProjectActivity
W/ActivityManager(  548): Activity pause timeout for ActivityRecord{52a1e314 u0 test.project.com/org.appcelerator.titanium.TiActivity t24 f}

A fix would be great, can't release my app at the moment :-(

I created a clean testproject which can be downloaded here: http://a.pomf.se/hnggbq.zip

e-m-s-y commented 9 years ago

I ran into the same problem and found a different way to hide the actionBar due XML. To do this create a folder called 'values' in 'platform/android/res'. Next, create a new file in the values map and name it 'no-actionbar.xml' upon creation paste the following code into that file:

`<?xml version="1.0" encoding="UTF-8"?>

` Save it and go to tiapp.xml. Add the following XML in your android tags or paste it after the ios tags if you haven't any android tags: ` ` That's it, now you have your actionBar disabled. Note: this only works on API level 14 and higher (android 3.0 and higher).