[TIMOB-25456] Android: Crash after calling Stringify on Ti.UI.Window
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-11-13T22:45:28.000+0000 |
Affected Version/s | Release 6.2.0 |
Fix Version/s | Release 7.0.0 |
Components | Android |
Labels | android |
Reporter | Yordan Banev |
Assignee | Yordan Banev |
Created | 2017-10-30T11:49:45.000+0000 |
Updated | 2017-11-23T17:26:46.000+0000 |
Description
Calling
Stringify
on a Window instance before it has been opened crashes the application.
*Test case:*
var win = Ti.UI.createWindow();
Ti.API.error(JSON.stringify(win));
win.open();
_Result_: Application crashes.
_Expected behavior_: Application should not crash.
*Console log:*
[WARN] : W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.support.v7.app.ActionBar.setDisplayOptions(int)’ on a null object reference
[WARN] : W/System.err: at org.appcelerator.titanium.proxy.ActionBarProxy.<init>(ActionBarProxy.java:58)
[WARN] : W/System.err: at org.appcelerator.titanium.proxy.ActivityProxy.getActionBar(ActivityProxy.java:258)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:196)
[WARN] : W/System.err: at org.appcelerator.kroll.KrollRuntime.runModule(KrollRuntime.java:243)
[WARN] : W/System.err: at org.appcelerator.titanium.TiLaunchActivity.loadActivityScript(TiLaunchActivity.java:128)
[WARN] : W/System.err: at org.appcelerator.titanium.TiLaunchActivity.windowCreated(TiLaunchActivity.java:183)
[WARN] : W/System.err: at org.appcelerator.titanium.TiRootActivity.windowCreated(TiRootActivity.java:172)
[WARN] : W/System.err: at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:684)
[WARN] : W/System.err: at org.appcelerator.titanium.TiLaunchActivity.onCreate(TiLaunchActivity.java:169)
[WARN] : W/System.err: at org.appcelerator.titanium.TiRootActivity.onCreate(TiRootActivity.java:161)
[WARN] : W/System.err: at android.app.Activity.performCreate(Activity.java:6679)
[WARN] : W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
[WARN] : W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
[WARN] : W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
[WARN] : W/System.err: at android.app.ActivityThread.-wrap12(ActivityThread.java)
[WARN] : W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
[WARN] : W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
[WARN] : W/System.err: at android.os.Looper.loop(Looper.java:154)
[WARN] : W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6119)
[WARN] : W/System.err: at java.lang.reflect.Method.invoke(Native Method)
[WARN] : W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
[WARN] : W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Getting the same error here, with SDK 6.3.0.GA. Is there any workaround for this? My log is below: {noformat} [ERROR] TiExceptionHandler: (main) [0,333] - Message: Uncaught Attempt to invoke virtual method ‘void android.support.v7.app.ActionBar.setDisplayOptions(int)’ on a null object reference {noformat}
I have a constructor for my windows, so that I can customize programmatically some window properties. Below is the code I'm using, it may help you identify the bug... PS: I tried to play with some timeouts (because Ti seems to lose reference of activity/actionBar) but did not have any luck.
FR passed; PR merged.
Thats great news! =] Can you provide us more information to workaround in current SDK version? Thanks!
Changes are seen in SDK 7.0.0.v20171114202841.
What about current projects that need to be released on CURRENT 6.3.0.GA SDK?
[~perdona] Please feel free to patch the following [5 lines](https://github.com/appcelerator/titanium_mobile/pull/9570/files#diff-795f7c4f31e823f6efcb79974c240224R58-R63) using the linked change. You just check-out the 6_3_X branch, which is the stable GA, apply the patch, compile it in build/ by using
node scons.js cleanbuild
and use the resulting SDK (will be 6.3.1). Hope that helps! Otherwise we'll grab a build for you ;-).Hans, thanks for the feedback. I'm trying to build the module here, but I'm getting the following {noformat} BUILD SUCCESSFUL Total time: 3 seconds path.js:7 throw new TypeError('Path must be a string. Received ' + inspect(path)); ^ TypeError: Path must be a string. Received null at assertPath (path.js:7:11) at Object.join (path.js:1213:7) at AndroidSDK.getPlatformDir (/Users/perdona/Dev/lab/TI/titanium_mobile/build/androidsdk.js:64:24) at Android.build (/Users/perdona/Dev/lab/TI/titanium_mobile/build/android.js:52:28) at /Users/perdona/Dev/lab/TI/titanium_mobile/build/scons-cleanbuild.js:95:26 at /Users/perdona/Dev/lab/TI/titanium_mobile/node_modules/async/dist/async.js:3047:16 at replenish (/Users/perdona/Dev/lab/TI/titanium_mobile/node_modules/async/dist/async.js:982:17) at /Users/perdona/Dev/lab/TI/titanium_mobile/node_modules/async/dist/async.js:986:9 at eachLimit$1 (/Users/perdona/Dev/lab/TI/titanium_mobile/node_modules/async/dist/async.js:3133:22) at Object.
Looks like your Android SDK / NDK path is not set correctly. Change with
appc ti setup android
. For example, my android-sdk is in/opt/android-sdk
and the android-ndk in/opt/android-ndk
.I generated a custom 6_3_X SDK (6.3.1) with this ticket being added, feel free to test it [~perdona]! Please note that we cannot do that all the time, so try to fix the build-setup as well to be more flexible for the future :-) Download: https://www.dropbox.com/s/zelfowjcypj4a1h/mobilesdk-6.3.1-perdona.zip?dl=1
Just tested and it seems to work fine without any errors... Huge thanks to Hans for providing support on this issue!