NativeScript: Split View Crash

@vbresults commented on Sat Feb 09 2019

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 5.1.1
  • Android Runtime: 5.1.0
  • Android API Level: 25

Describe the bug If you are outside the NS app (i.e. Settings app) and NS launches from tns run android, the screen is split into two with a slider. If you choose to move the slider up to dismiss the non-NS app, the NS app will crash with the attached error.

To Reproduce Move the slider up to dismiss the non-NS app, the NS app will crash with the attached error.

Additional context

02-09 12:22:52.003  6010  6010 W System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: 
02-09 12:22:52.003  6010  6010 W System.err: Calling js method onCreate failed
02-09 12:22:52.003  6010  6010 W System.err: 
02-09 12:22:52.003  6010  6010 W System.err: Error: java.lang.NullPointerException: Attempt to write to field 'android.view.View org.nativescript.widgets.MeasureSpecs.child' on a null object reference
02-09 12:22:52.003  6010  6010 W System.err:     org.nativescript.widgets.GridLayout.removeFromMap(GridLayout.java:229)
02-09 12:22:52.003  6010  6010 W System.err:     org.nativescript.widgets.GridLayout.removeView(GridLayout.java:135)
02-09 12:22:52.003  6010  6010 W System.err:     com.tns.Runtime.callJSMethodNative(Native Method)
02-09 12:22:52.003  6010  6010 W System.err:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1120)
02-09 12:22:52.003  6010  6010 W System.err:     com.tns.Runtime.callJSMethodImpl(Runtime.java:1000)
02-09 12:22:52.003  6010  6010 W System.err:     com.tns.Runtime.callJSMethod(Runtime.java:987)
02-09 12:22:52.003  6010  6010 W System.err:     com.tns.Runtime.callJSMethod(Runtime.java:967)
02-09 12:22:52.003  6010  6010 W System.err:     com.tns.Runtime.callJSMethod(Runtime.java:959)
02-09 12:22:52.003  6010  6010 W System.err:     com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:18)
02-09 12:22:52.003  6010  6010 W System.err:     android.app.Activity.performCreate(Activity.java:6679)
02-09 12:22:52.003  6010  6010 W System.err:     android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
02-09 12:22:52.003  6010  6010 W System.err:     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
02-09 12:22:52.003  6010  6010 W System.err:     android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
02-09 12:22:52.003  6010  6010 W System.err:     android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4519)
02-09 12:22:52.003  6010  6010 W System.err:     android.app.ActivityThread.-wrap19(ActivityThread.java)
02-09 12:22:52.003  6010  6010 W System.err:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1483)
02-09 12:22:52.003  6010  6010 W System.err:     android.os.Handler.dispatchMessage(Handler.java:102)
02-09 12:22:52.003  6010  6010 W System.err:     android.os.Looper.loop(Looper.java:154)
02-09 12:22:52.003  6010  6010 W System.err:     android.app.ActivityThread.main(ActivityThread.java:6119)
02-09 12:22:52.003  6010  6010 W System.err:     java.lang.reflect.Method.invoke(Native Method)
02-09 12:22:52.003  6010  6010 W System.err:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
02-09 12:22:52.003  6010  6010 W System.err:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
02-09 12:22:52.003  6010  6010 W System.err: File: "file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view/view.js, line: 733, column: 23
02-09 12:22:52.003  6010  6010 W System.err: 
02-09 12:22:52.003  6010  6010 W System.err: StackTrace: 
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'CustomLayoutView._removeViewFromNativeVisualTree', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view/view.js', line: 733, column: 24
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'WebView._tearDownUI', file:'file:///data/data/com.example.app/files/app/tns_modules/nativescript-web-view/web-view.js', line: 147, column: 25
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'ViewBase._setupUI', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 486, column: 18
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 533, column: 19
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'LayoutBaseCommon.eachChildView', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/layouts/layout-base-common.js', line: 125, column: 26
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'ViewCommon.eachChild', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view/view-common.js', line: 884, column: 14
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'ViewBase._setupUI', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 532, column: 14
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 533, column: 19
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'LayoutBaseCommon.eachChildView', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/layouts/layout-base-common.js', line: 125, column: 26
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'ViewCommon.eachChild', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view/view-common.js', line: 884, column: 14
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'ViewBase._setupUI', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 532, column: 14
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 533, column: 19
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'ContentView.eachChildView', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/content-view/content-view.js', line: 70, column: 13
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'PageBase.eachChildView', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/page/page-common.js', line: 120, column: 40
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'ViewCommon.eachChild', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view/view-common.js', line: 884, column: 14
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'ViewBase._setupUI', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 532, column: 14
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 533, column: 19
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'FrameBase.eachChildView', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 368, column: 13
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'ViewCommon.eachChild', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view/view-common.js', line: 884, column: 14
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'ViewBase._setupUI', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 532, column: 14
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 917, column: 22
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 763, column: 14
02-09 12:22:52.003  6010  6010 W System.err: 	Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 20, column: 25
02-09 12:22:52.003  6010  6010 W System.err: 
02-09 12:22:52.003  6010  6010 W System.err: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
02-09 12:22:52.003  6010  6010 W System.err: 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
02-09 12:22:52.003  6010  6010 W System.err: 	at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4519)
02-09 12:22:52.003  6010  6010 W System.err: 	at android.app.ActivityThread.-wrap19(ActivityThread.java)
02-09 12:22:52.003  6010  6010 W System.err: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1483)
02-09 12:22:52.003  6010  6010 W System.err: 	at android.os.Handler.dispatchMessage(Handler.java:102)
02-09 12:22:52.003  6010  6010 W System.err: 	at android.os.Looper.loop(Looper.java:154)
02-09 12:22:52.003  6010  6010 W System.err: 	at android.app.ActivityThread.main(ActivityThread.java:6119)
02-09 12:22:52.003  6010  6010 W System.err: 	at java.lang.reflect.Method.invoke(Native Method)
02-09 12:22:52.003  6010  6010 W System.err: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
02-09 12:22:52.003  6010  6010 W System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
02-09 12:22:52.003  6010  6010 W System.err: Caused by: com.tns.NativeScriptException: 
02-09 12:22:52.003  6010  6010 W System.err: Calling js method onCreate failed
02-09 12:22:52.003  6010  6010 W System.err: 
02-09 12:22:52.003  6010  6010 W System.err: Error: java.lang.NullPointerException: Attempt to write to field 'android.view.View org.nativescript.widgets.MeasureSpecs.child' on a null object reference
02-09 12:22:52.003  6010  6010 W System.err:     org.nativescript.widgets.GridLayout.removeFromMap(GridLayout.java:229)
02-09 12:22:52.004  6010  6010 W System.err:     org.nativescript.widgets.GridLayout.removeView(GridLayout.java:135)
02-09 12:22:52.004  6010  6010 W System.err:     com.tns.Runtime.callJSMethodNative(Native Method)
02-09 12:22:52.004  6010  6010 W System.err:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1120)
02-09 12:22:52.004  6010  6010 W System.err:     com.tns.Runtime.callJSMethodImpl(Runtime.java:1000)
02-09 12:22:52.004  6010  6010 W System.err:     com.tns.Runtime.callJSMethod(Runtime.java:987)
02-09 12:22:52.004  6010  6010 W System.err:     com.tns.Runtime.callJSMethod(Runtime.java:967)
02-09 12:22:52.004  6010  6010 W System.err:     com.tns.Runtime.callJSMethod(Runtime.java:959)
02-09 12:22:52.004  6010  6010 W System.err:     com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:18)
02-09 12:22:52.004  6010  6010 W System.err:     android.app.Activity.performCreate(Activity.java:6679)
02-09 12:22:52.004  6010  6010 W System.err:     android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
02-09 12:22:52.004  6010  6010 W System.err:     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
02-09 12:22:52.004  6010  6010 W System.err:     android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
02-09 12:22:52.004  6010  6010 W System.err:     android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4519)
02-09 12:22:52.004  6010  6010 W System.err:     android.app.ActivityThread.-wrap19(ActivityThread.java)
02-09 12:22:52.004  6010  6010 W System.err:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1483)
02-09 12:22:52.004  6010  6010 W System.err:     android.os.Handler.dispatchMessage(Handler.java:102)
02-09 12:22:52.004  6010  6010 W System.err:     android.os.Looper.loop(Looper.java:154)
02-09 12:22:52.004  6010  6010 W System.err:     android.app.ActivityThread.main(ActivityThread.java:6119)
02-09 12:22:52.004  6010  6010 W System.err:     java.lang.reflect.Method.invoke(Native Method)
02-09 12:22:52.004  6010  6010 W System.err:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
02-09 12:22:52.004  6010  6010 W System.err:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
02-09 12:22:52.004  6010  6010 W System.err: File: "file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view/view.js, line: 733, column: 23
02-09 12:22:52.004  6010  6010 W System.err: 
02-09 12:22:52.004  6010  6010 W System.err: StackTrace: 
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'CustomLayoutView._removeViewFromNativeVisualTree', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view/view.js', line: 733, column: 24
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'WebView._tearDownUI', file:'file:///data/data/com.example.app/files/app/tns_modules/nativescript-web-view/web-view.js', line: 147, column: 25
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'ViewBase._setupUI', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 486, column: 18
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 533, column: 19
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'LayoutBaseCommon.eachChildView', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/layouts/layout-base-common.js', line: 125, column: 26
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'ViewCommon.eachChild', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view/view-common.js', line: 884, column: 14
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'ViewBase._setupUI', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 532, column: 14
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 533, column: 19
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'LayoutBaseCommon.eachChildView', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/layouts/layout-base-common.js', line: 125, column: 26
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'ViewCommon.eachChild', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view/view-common.js', line: 884, column: 14
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'ViewBase._setupUI', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 532, column: 14
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 533, column: 19
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'ContentView.eachChildView', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/content-view/content-view.js', line: 70, column: 13
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'PageBase.eachChildView', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/page/page-common.js', line: 120, column: 40
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'ViewCommon.eachChild', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view/view-common.js', line: 884, column: 14
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'ViewBase._setupUI', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 532, column: 14
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 533, column: 19
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'FrameBase.eachChildView', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 368, column: 13
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'ViewCommon.eachChild', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view/view-common.js', line: 884, column: 14
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'ViewBase._setupUI', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 532, column: 14
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 917, column: 22
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 763, column: 14
02-09 12:22:52.004  6010  6010 W System.err: 	Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/com.example.app/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 20, column: 25
02-09 12:22:52.004  6010  6010 W System.err: 
02-09 12:22:52.004  6010  6010 W System.err: 	at com.tns.Runtime.callJSMethodNative(Native Method)
02-09 12:22:52.004  6010  6010 W System.err: 	at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1120)
02-09 12:22:52.004  6010  6010 W System.err: 	at com.tns.Runtime.callJSMethodImpl(Runtime.java:1000)
02-09 12:22:52.004  6010  6010 W System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:987)
02-09 12:22:52.004  6010  6010 W System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:967)
02-09 12:22:52.004  6010  6010 W System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:959)
02-09 12:22:52.004  6010  6010 W System.err: 	at com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:18)
02-09 12:22:52.004  6010  6010 W System.err: 	at android.app.Activity.performCreate(Activity.java:6679)
02-09 12:22:52.004  6010  6010 W System.err: 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
02-09 12:22:52.004  6010  6010 W System.err: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
02-09 12:22:52.004  6010  6010 W System.err: 	... 10 more
02-09 12:22:52.004  6010  6010 W System.err: Caused by: java.lang.NullPointerException: Attempt to write to field 'android.view.View org.nativescript.widgets.MeasureSpecs.child' on a null object reference
02-09 12:22:52.004  6010  6010 W System.err: 	at org.nativescript.widgets.GridLayout.removeFromMap(GridLayout.java:229)
02-09 12:22:52.004  6010  6010 W System.err: 	at org.nativescript.widgets.GridLayout.removeView(GridLayout.java:135)

@tsonevn commented on Mon Feb 11 2019

Hi @vbresults, I tested your scenario in a sample project on Android device, however, was unable to recreate the issue. For your convenience, I am attaching the project. Please review it and make the needed changes, that will help us in recreating the problem.

Meanwhile, make sure that you have added keyboard|smallestScreenSize|screenLayout|locale|uiMode options in the configChanges in your AndroidManifest.xml file.

For example:

android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|locale|uiMode"

Archive.zip

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Hi @xlmnxp, I found out that the crash in the project is related to the custom login implemented inside of the TabView’s loaded event(disableFocusSearchBar callback method in your code) in posts.component.ts. In disableFocusSearchBar, you are using the removeViewAt native method to remove one of the TabView’s child views(this.tabview.nativeElement.android.removeViewAt(1);). This method will remove the needed child view successfully when the page is initially loaded. However, when you make forward and them backwards navigation, you will try to remove the non-existing native child view again. To solve your case, you need first to check if the child view exists and then try to remove it. For example:

disableFocusSearchBar() {
    var searchBar: SearchBar = <SearchBar>this.searchBar.nativeElement;
    if (isAndroid) {
      searchBar.parent.android.setFocusableInTouchMode(true);
      searchBar.parent.android.setFocusable(true);
      searchBar.nativeView.setFocusable(false);
      searchBar.nativeView.clearFocus();
      if(this.tabview.nativeElement.android.getChildAt(1)){
        this.tabview.nativeElement.android.removeViewAt(1);
      }
    } else {
      this.tabview.nativeElement.ios.tabBar.hidden = true;
    }

    ad.dismissSoftInput();
  }

@tsonevn Fix the problem Thank you for the solution 😄


I’m very sorry to bother you