[AC-6371] Android DrawerLayout parameters/object not accessible within eventListener "change"
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | n/a |
| Status | Resolved |
| Resolution | Done |
| Resolution Date | 2019-10-29T20:05:38.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | Titanium SDK & CLI |
| Labels | android, drawerlayout, event, parameters |
| Reporter | Arjan |
| Assignee | Shak Hossain |
| Created | 2019-09-19T10:22:00.000+0000 |
| Updated | 2019-10-29T20:05:39.000+0000 |
Description
I was trying to get the state of the drawer view by attaching the "change" event. But within the listener you can't access any parameters from the current object. No local reference.
SDK; 8.1.1.GA
Platform: Android
Code example (index controller);
var win = Ti.UI.createWindow();
var leftView = Ti.UI.createView({ backgroundColor:'red' });
var centerView = Ti.UI.createView({ backgroundColor:'yellow' });
var rightView = Ti.UI.createView({ backgroundColor:'orange' });
var drawer = Ti.UI.Android.createDrawerLayout({
leftView: leftView,
centerView: centerView,
rightView: rightView
});
var btn = Ti.UI.createButton({ title: 'RIGHT' });
btn.addEventListener('click', function() {
drawer.toggleRight();
});
centerView.add(btn);
win.addEventListener('open', function(){
console.log('window opened');
var activity = win.getActivity(),
actionBar = activity.getActionBar();
if (actionBar) {
actionBar.displayHomeAsUp = true;
actionBar.onHomeIconItemSelected = function() {
drawer.toggleLeft();
};
}
});
win.addEventListener('close', function(){
console.log('window closed');
});
drawer.addEventListener('open', function() {
console.log('drawer opened');
});
drawer.addEventListener('close', function() {
console.log('drawer closed');
});
drawer.addEventListener("change", onDrawerChange);
function onDrawerChange(e) {
console.log("[ drawerView has changed");
console.info(this); // error
console.info(e); // error
}
win.add(drawer);
win.open();
Errors;
[ERROR] : TiExceptionHandler: (main) [386,30549] ti:/titanium.js:178
[ERROR] : TiExceptionHandler: serialized[k] = this[k];
[ERROR] : TiExceptionHandler: ^
[ERROR] : TiExceptionHandler: Error: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
[ERROR] : TiExceptionHandler: at ListItem.value (ti:/titanium.js:178:24)
[ERROR] : TiExceptionHandler: at JSON.stringify (<anonymous>)
[ERROR] : TiExceptionHandler: at ti:/console.js:26:63
[ERROR] : TiExceptionHandler: at Array.map (<anonymous>)
[ERROR] : TiExceptionHandler: at join (ti:/console.js:18:53)
[ERROR] : TiExceptionHandler: at Object.exports.info (ti:/console.js:52:20)
[ERROR] : TiExceptionHandler: at DrawerLayout.onDrawerChange (/alloy/controllers/appWindow.js:174:9)
[ERROR] : TiExceptionHandler: at DrawerLayout.value (ti:/events.js:50:21)
[ERROR] : TiExceptionHandler: at DrawerLayout.value (ti:/events.js:102:19)
[ERROR] : TiExceptionHandler:
[ERROR] : TiExceptionHandler: ti.modules.titanium.ui.widget.listview.TiListItem.handleAccessory(TiListItem.java:64)
[ERROR] : TiExceptionHandler: ti.modules.titanium.ui.widget.listview.TiListItem.processProperties(TiListItem.java:50)
[ERROR] : TiExceptionHandler: org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:1345)
[ERROR] : TiExceptionHandler: org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:508)
[ERROR] : TiExceptionHandler: org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:498)
[ERROR] : TiExceptionHandler: org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:464)
[ERROR] : TiExceptionHandler: org.appcelerator.titanium.proxy.TiViewProxy.getBackgroundSelectedColor(TiViewProxy.java:1074)
[ERROR] : TiExceptionHandler: org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[ERROR] : TiExceptionHandler: org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:63)
[ERROR] : TiExceptionHandler: org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:976)
[ERROR] : V8Exception: Exception occurred at ti:/titanium.js:178: Uncaught Error: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
Hello, I am not able to reproduce the error in SDK 8.2.0.GA and I can log the change. Can you try with that SDK? Thanks.
Hi Sharif, Ran a test on 8.2.1.GA, result: 1) the errors are gone 2) parent window events (open/closed) are still triggerred though I used above example, copied it to a new project, compiled it with 8.2.1.GA Console output;
[INFO] : [ drawerView has changed [INFO] : {"rightView":{"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":296,"y":0,"height":612},"rect":{"width":296,"x":0,"y":0,"absoluteX":360,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":"orange","backgroundFocusedColor":null,"apiName":"Ti.UI.View","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true},"centerView":{"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[{"shadowRadius":1,"enabled":true,"title":"RIGHT","hiddenBehavior":4,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":88,"y":0,"height":48},"rect":{"width":88,"x":136,"y":282,"absoluteX":136,"absoluteY":362,"height":48},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":null,"backgroundFocusedColor":null,"apiName":"Ti.UI.Button","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_events":{"click":{}}}],"size":{"x":0,"width":360,"y":0,"height":612},"rect":{"width":360,"x":0,"y":0,"absoluteX":0,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":"yellow","backgroundFocusedColor":null,"apiName":"Ti.UI.View","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_children":[{"shadowRadius":1,"enabled":true,"title":"RIGHT","hiddenBehavior":4,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":88,"y":0,"height":48},"rect":{"width":88,"x":136,"y":282,"absoluteX":136,"absoluteY":362,"height":48},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":null,"backgroundFocusedColor":null,"apiName":"Ti.UI.Button","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_events":{"click":{}}}]},"isLeftOpen":true,"isRightVisible":false,"drawerLockMode":3,"toolbarEnabled":true,"drawerIndicatorEnabled":true,"isRightOpen":false,"leftView":{"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":296,"y":0,"height":612},"rect":{"width":296,"x":0,"y":0,"absoluteX":0,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":"red","backgroundFocusedColor":null,"apiName":"Ti.UI.View","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true},"isLeftVisible":true,"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":360,"y":0,"height":612},"rect":{"width":360,"x":0,"y":0,"absoluteX":0,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":null,"backgroundFocusedColor":null,"apiName":"Ti.Proxy","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_events":{"open":{},"close":{},"change":{}}} [INFO] : {"type":"change","source":{"rightView":{"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":296,"y":0,"height":612},"rect":{"width":296,"x":0,"y":0,"absoluteX":360,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":"orange","backgroundFocusedColor":null,"apiName":"Ti.UI.View","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true},"centerView":{"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[{"shadowRadius":1,"enabled":true,"title":"RIGHT","hiddenBehavior":4,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":88,"y":0,"height":48},"rect":{"width":88,"x":136,"y":282,"absoluteX":136,"absoluteY":362,"height":48},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":null,"backgroundFocusedColor":null,"apiName":"Ti.UI.Button","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_events":{"click":{}}}],"size":{"x":0,"width":360,"y":0,"height":612},"rect":{"width":360,"x":0,"y":0,"absoluteX":0,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":"yellow","backgroundFocusedColor":null,"apiName":"Ti.UI.View","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_children":[{"shadowRadius":1,"enabled":true,"title":"RIGHT","hiddenBehavior":4,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":88,"y":0,"height":48},"rect":{"width":88,"x":136,"y":282,"absoluteX":136,"absoluteY":362,"height":48},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":null,"backgroundFocusedColor":null,"apiName":"Ti.UI.Button","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_events":{"click":{}}}]},"isLeftOpen":true,"isRightVisible":false,"drawerLockMode":3,"toolbarEnabled":true,"drawerIndicatorEnabled":true,"isRightOpen":false,"leftView":{"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":296,"y":0,"height":612},"rect":{"width":296,"x":0,"y":0,"absoluteX":0,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":"red","backgroundFocusedColor":null,"apiName":"Ti.UI.View","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true},"isLeftVisible":true,"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":360,"y":0,"height":612},"rect":{"width":360,"x":0,"y":0,"absoluteX":0,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":null,"backgroundFocusedColor":null,"apiName":"Ti.Proxy","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_events":{"open":{},"close":{},"change":{}}},"dragging":false,"state":2,"settling":true,"idle":false,"bubbles":true,"cancelBubble":false} [INFO] : drawer closed [INFO] : [ drawerView has changed [INFO] : {"rightView":{"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":296,"y":0,"height":612},"rect":{"width":296,"x":0,"y":0,"absoluteX":360,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":"orange","backgroundFocusedColor":null,"apiName":"Ti.UI.View","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true},"centerView":{"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[{"shadowRadius":1,"enabled":true,"title":"RIGHT","hiddenBehavior":4,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":88,"y":0,"height":48},"rect":{"width":88,"x":136,"y":282,"absoluteX":136,"absoluteY":362,"height":48},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":null,"backgroundFocusedColor":null,"apiName":"Ti.UI.Button","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_events":{"click":{}}}],"size":{"x":0,"width":360,"y":0,"height":612},"rect":{"width":360,"x":0,"y":0,"absoluteX":0,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":"yellow","backgroundFocusedColor":null,"apiName":"Ti.UI.View","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_children":[{"shadowRadius":1,"enabled":true,"title":"RIGHT","hiddenBehavior":4,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":88,"y":0,"height":48},"rect":{"width":88,"x":136,"y":282,"absoluteX":136,"absoluteY":362,"height":48},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":null,"backgroundFocusedColor":null,"apiName":"Ti.UI.Button","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_events":{"click":{}}}]},"isLeftOpen":false,"isRightVisible":false,"drawerLockMode":3,"toolbarEnabled":true,"drawerIndicatorEnabled":true,"isRightOpen":false,"leftView":{"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":296,"y":0,"height":612},"rect":{"width":296,"x":0,"y":0,"absoluteX":-296,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":"red","backgroundFocusedColor":null,"apiName":"Ti.UI.View","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true},"isLeftVisible":false,"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":360,"y":0,"height":612},"rect":{"width":360,"x":0,"y":0,"absoluteX":0,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":null,"backgroundFocusedColor":null,"apiName":"Ti.Proxy","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_events":{"open":{},"close":{},"change":{}}} [INFO] : {"type":"change","source":{"rightView":{"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":296,"y":0,"height":612},"rect":{"width":296,"x":0,"y":0,"absoluteX":360,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":"orange","backgroundFocusedColor":null,"apiName":"Ti.UI.View","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true},"centerView":{"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[{"shadowRadius":1,"enabled":true,"title":"RIGHT","hiddenBehavior":4,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":88,"y":0,"height":48},"rect":{"width":88,"x":136,"y":282,"absoluteX":136,"absoluteY":362,"height":48},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":null,"backgroundFocusedColor":null,"apiName":"Ti.UI.Button","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_events":{"click":{}}}],"size":{"x":0,"width":360,"y":0,"height":612},"rect":{"width":360,"x":0,"y":0,"absoluteX":0,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":"yellow","backgroundFocusedColor":null,"apiName":"Ti.UI.View","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_children":[{"shadowRadius":1,"enabled":true,"title":"RIGHT","hiddenBehavior":4,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":88,"y":0,"height":48},"rect":{"width":88,"x":136,"y":282,"absoluteX":136,"absoluteY":362,"height":48},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":null,"backgroundFocusedColor":null,"apiName":"Ti.UI.Button","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_events":{"click":{}}}]},"isLeftOpen":false,"isRightVisible":false,"drawerLockMode":3,"toolbarEnabled":true,"drawerIndicatorEnabled":true,"isRightOpen":false,"leftView":{"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":296,"y":0,"height":612},"rect":{"width":296,"x":0,"y":0,"absoluteX":-296,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":"red","backgroundFocusedColor":null,"apiName":"Ti.UI.View","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true},"isLeftVisible":false,"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"children":[],"size":{"x":0,"width":360,"y":0,"height":612},"rect":{"width":360,"x":0,"y":0,"absoluteX":0,"absoluteY":80,"height":612},"backgroundSelectedColor":null,"backgroundDisabledColor":null,"keepScreenOn":false,"backgroundColor":null,"backgroundFocusedColor":null,"apiName":"Ti.Proxy","bubbleParent":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_events":{"open":{},"close":{},"change":{}}},"dragging":false,"state":0,"settling":false,"idle":true,"bubbles":true,"cancelBubble":false} [INFO] : window closed