Uploaded image for project: 'Appcelerator - INBOX'
  1. Appcelerator - INBOX
  2. AC-6371

Android DrawerLayout parameters/object not accessible within eventListener "change"

    Details

      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
      
      

        Attachments

          Activity

            People

            • Assignee:
              shossain Shak Hossain (Inactive)
              Reporter:
              arif Arjan
            • Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Git Source Code