Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Index out of bound

Hello

I am converting my iPhone app to Android.

I'm having a problem with my tableview. I can populate it correctly and it loads perfectly. Now when I scroll it crashes with the error:

W/dalvikvm(  774): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/TiUncaughtHandler(  774): (main) [6622,317311] Sending event: exception on thread: main msg:java.lang.ArrayIndexOutOfBoundsException; Titanium 1.7.2,2011/07/21 09:36,97c3689
E/TiUncaughtHandler(  774): java.lang.ArrayIndexOutOfBoundsException
E/TiUncaughtHandler(  774):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.applyChildProxies(TiTableViewRowProxyItem.java:158)
E/TiUncaughtHandler(  774):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.refreshControls(TiTableViewRowProxyItem.java:138)
E/TiUncaughtHandler(  774):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.setRowData(TiTableViewRowProxyItem.java:273)
E/TiUncaughtHandler(  774):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.setRowData(TiTableViewRowProxyItem.java:77)
E/TiUncaughtHandler(  774):     at ti.modules.titanium.ui.widget.tableview.TiTableView$TTVListAdapter.getView(TiTableView.java:204)

What could this ArrayIndexOutOfBoundsException be? Where do I have to look for it? How can I locate where the problem occurs?

I haven't used any array's except the data for the tableview.

But the strange this is that this problem only happens when I start scrolling down. Can anyone give me a bit more explanation about this error? I thought the outofbound exception only could occur if you call a place in the array larger than the array itself? But since all the data is already loaded I'm guessing that couldn't be the problem?

I'm using Titanium SDK 1.7.2.
Thanks in advance!

Tjeu

— asked August 5th 2011 by Tjeu Vdw
  • android
  • arrayindexoutofbound
  • error
  • tableview
0 Comments

6 Answers

  • I resolved this bug with disabling the classname attribute on the rows of the tableview.

    — answered October 17th 2011 by jb cazaux
    permalink
    3 Comments
    • I also solve this problem by removing className attribute of row…..

      — commented April 12th 2012 by nilesh kashid
    • Was there any affect on performance?

      — commented June 12th 2012 by Artem Pervenyonok
    • Disabling classname will allways affect to the performance. The best you can do is to identify every kind of row that this table has, and change the classname accordingly. For example, maybe you're adding an image in some rows. Then you must set a different classname for these rows than the ones that doesn't have the image. Something like "msg" and "msgimg".

      — commented January 24th 2013 by Lluis Gerard Lopez
  • Im also having this issue. I build a custom row that can have different views depending on the data. I have removed the classname property but I still get the following error when scrolling:

    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924): (main) [2971,12720] Sending event: exception on thread: main msg:java.lang.ArrayIndexOutOfBoundsException; Titanium 1.7.2,2011/07/21 09:36,97c3689
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924): java.lang.ArrayIndexOutOfBoundsException
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.applyChildProxies(TiTableViewRowProxyItem.java:158)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.applyChildProxies(TiTableViewRowProxyItem.java:161)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.refreshControls(TiTableViewRowProxyItem.java:138)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.setRowData(TiTableViewRowProxyItem.java:273)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.setRowData(TiTableViewRowProxyItem.java:77)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at ti.modules.titanium.ui.widget.tableview.TiTableView$TTVListAdapter.getView(TiTableView.java:204)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at android.widget.AbsListView.obtainView(AbsListView.java:1336)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at android.widget.ListView.makeAndAddView(ListView.java:1781)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at android.widget.ListView.fillDown(ListView.java:654)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at android.widget.ListView.fillGap(ListView.java:625)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at android.widget.AbsListView.trackMotionScroll(AbsListView.java:3010)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:2542)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at android.os.Handler.handleCallback(Handler.java:587)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at android.os.Handler.dispatchMessage(Handler.java:92)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at android.os.Looper.loop(Looper.java:143)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at android.app.ActivityThread.main(ActivityThread.java:5073)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at java.lang.reflect.Method.invokeNative(Native Method)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at java.lang.reflect.Method.invoke(Method.java:521)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    08-19 13:41:19.863: ERROR/TiUncaughtHandler(20924):     at dalvik.system.NativeStart.main(Native Method)
    08-19 13:41:19.883: ERROR/AndroidRuntime(20924): FATAL EXCEPTION: main
    08-19 13:41:19.883: ERROR/AndroidRuntime(20924): java.lang.ArrayIndexOutOfBoundsException
    08-19 13:41:19.883: ERROR/AndroidRuntime(20924):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.applyChildProxies(TiTableViewRowProxyItem.java:158)
    08-19 13:41:19.883: ERROR/AndroidRuntime(20924):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.applyChildProxies(TiTableViewRowProxyItem.java:161)
    08-19 13:41:19.883: ERROR/AndroidRuntime(20924):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.refreshControls(TiTableViewRowProxyItem.java:138)
    08-19 13:41:19.883: ERROR/AndroidRuntime(20924):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.setRowData(TiTableViewRowProxyItem.java:273)
    08-19 13:41:19.883: ERROR/AndroidRuntime(20924):     at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.setRowData(TiTableViewRowProxyItem.java:77)
    08-19 13:41:19.883: ERROR/AndroidRuntime(20924):     at ti.modules.titanium.ui.widget.tableview.TiTableView$TTVListAdapter.getView(TiTableView.java:204)
    08-19 13:41:19.883: ERROR/AndroidRuntime(20924):     at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
    08-19 13:41:19.883: ERROR/AndroidRuntime(20924):     at android.widget.AbsListView.obtainView(AbsListView.java:1336)
    08-19 13:41:19.883: ERROR/AndroidRuntime(20924):     at android.widget.ListView.makeAndAddView(ListView.java:1781)
    

    etc…..

    — answered August 19th 2011 by andrew royce
    permalink
    2 Comments
    • I figured it out, when i was building the custom rows some views would be added depending on a variable, I disabled this so all views were added no matter what and now it works fine..

      — commented August 19th 2011 by andrew royce
    • @Andrew… Even in my case I was building row with some conditional views which was causing the error. Thanks, your comment actually helped to understand the problem. :)

      — commented April 13th 2012 by Saurabh Bongale
  • Have you added Scroll event for tableView??????

    Can u please post the code…

    Regards,
    MONY

    — answered August 5th 2011 by MONY desu
    permalink
    1 Comment
    • No, I don't have a scroll event for my tableview. The weird thing is I used the exact same method to create my tableview on my other page, and there it doesn't show this error.

      My creation of the tableview:

      //Create the tableview
      var tableview = Titanium.UI.createTableView({
          style: Ti.UI.iPhone.TableViewStyle.GROUPED,
          minRowHeight: 40,
          search: search,
          filterAttribute: 'filter'
      });
      

      and when setting the data:

      tableview.data = data;
      

      I only have a click event added to the table:

      tableview.addEventListener('click', function(e){
              //When clicked on the calendar button, write data to calendar
          if (e.source.name == "calendarButton"){
              writeFavoritesToCalendar();
          } 
          else if (e.rowData.id) {
              var win = null;
              if (Titanium.Platform.name == "android") {
                  win = Titanium.UI.createWindow({
                      url: 'session/detail.js',
                      title: 'Session details'
                  });
              }
              else {
                  win = Titanium.UI.createWindow({
                      url: 'session/detail.js',
                      title: 'Session details',
                      backgroundColor: '#fff',
                      barColor: '#111'
                  });
              }
      
              win.sessionId = e.rowData.id;
              win.color = e.rowData.backgroundColor;
      
              Titanium.UI.currentTab.open(win, {
                  animated: true
              });
          }
          else {
              alert('No data found for this record');
          };
          });
      

      — commented August 5th 2011 by Tjeu Vdw
  • I'm using Titanium Mobile 2.0.1.GA2, and I also solved this problem by removing the classname attribute of createTableViewRow. Thanks for the solution.

    — answered May 15th 2012 by Daniel Åkerud
    permalink
    0 Comments
  • Yes, it's className problem.

    — answered October 19th 2012 by Jarek Wasowski
    permalink
    1 Comment
    • No body, it's actually providing at least an actual simple sample to dig into this problem in order to narrow it down or even fix a potential Titanium bug. You might want to review this Guide to make some progress here.

      In regards with className property, usage and overall guidelines will be described and well documented here: Ti API: Need best practices for TableViews/Rows and class names

      — commented November 21st 2012 by Eduardo Gomez
  • yes className is creating the havoc.. while scolling the tableview…..so please remove className property

    — answered March 26th 2013 by yash maharshi
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.