Titanium Community Questions & Answer Archive

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

TableViewSection on Android crashes app

I'm trying to use TableViewSections according to the example on the API page:

somearray[key] = Ti.UI.createTableViewSection();
somearray[key].headerTitle = 'blah blah';
somearray[key].add( mytableviewrow );

mytableview.add( somearray[key] );

The app crashes (in the emulator) upon mytableview.add().

— asked June 2nd 2010 by Markus Birth
  • android
  • crash
  • tableview
  • tableviewsection
3 Comments
  • can you post output from the console?

    — commented June 2nd 2010 by Kevin Whinnery
  • Set your Log Level to Trace. The crash detail should be there at that level.

    — commented June 2nd 2010 by Don Thorp
  • The first line is my debug output just one line before tableView.add( data[i] ). Then it crashes.

    [DEBUG] [12,84607] Now adding section for day 14785
    [TRACE] D/AndroidRuntime( 232): Shutting down VM
    [TRACE] W/dalvikvm( 232): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
    [TRACE] E/TiUncaughtHandler( 232): (main) [13,84620] Sending event: exception on thread: main msg:java.lang.NullPointerException
    [TRACE] E/TiUncaughtHandler( 232): java.lang.NullPointerException
    [TRACE] E/TiUncaughtHandler( 232): at org.appcelerator.titanium.TiProxy.setModelListener(Unknown Source)
    [TRACE] E/TiUncaughtHandler( 232): at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(Unknown Source)
    [TRACE] E/TiUncaughtHandler( 232): at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(Unknown Source)
    [TRACE] E/TiUncaughtHandler( 232): at org.appcelerator.titanium.proxy.TiViewProxy.getView(Unknown Source)
    [TRACE] E/TiUncaughtHandler( 232): at org.appcelerator.titanium.proxy.TiViewProxy.handleAdd(Unknown Source)
    [TRACE] E/TiUncaughtHandler( 232): at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(Unknown Source)
    [TRACE] E/TiUncaughtHandler( 232): at ti.modules.titanium.ui.TableViewProxy.handleMessage(Unknown Source)
    [TRACE] E/TiUncaughtHandler( 232): at android.os.Handler.dispatchMessage(Handler.java:95)
    [TRACE] E/TiUncaughtHandler( 232): at android.os.Looper.loop(Looper.java:123)
    [TRACE] E/TiUncaughtHandler( 232): at android.app.ActivityThread.main(ActivityThread.java:4203)
    [TRACE] E/TiUncaughtHandler( 232): at java.lang.reflect.Method.invokeNative(Native Method)
    [TRACE] E/TiUncaughtHandler( 232): at java.lang.reflect.Method.invoke(Method.java:521)
    [TRACE] E/TiUncaughtHandler( 232): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
    [TRACE] E/TiUncaughtHandler( 232): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
    [TRACE] E/TiUncaughtHandler( 232): at dalvik.system.NativeStart.main(Native Method)
    [TRACE] D/TiApplication( 232): (main) [57,84677] Analytics Event: type=ti.crash
    [TRACE] D/TiApplication( 232): event=ti.crash
    [TRACE] D/TiApplication( 232): timestamp=2010-06-03T07:40:57.765+0000
    [TRACE] D/TiApplication( 232): mid=4a191a63-8eb8-443a-9596-a24c252b5653
    [TRACE] D/TiApplication( 232): sid=34b39441-1190-47a9-abbc-0b1d93a700e3
    [TRACE] D/TiApplication( 232): aguid=None
    [TRACE] D/TiApplication( 232): isJSON=true
    [TRACE] D/TiApplication( 232): payload={"value":"thread_namemain\nthread_id1\nerror_msgjava.lang.NullPointerException\n<<<<<<<<<<<<<<< STACK TRACE >>>>>>>>>>>>>>>\norg.appcelerator.titanium.TiProxy.setModelListener(Unknown Source)\norg.appcelerator.titanium.proxy.TiViewProxy.realizeViews(Unknown Source)\norg.appcelerator.titanium.proxy.TiViewProxy.handleGetView(Unknown Source)\norg.appcelerator.titanium.proxy.TiViewProxy.getView(Unknown Source)\norg.appcelerator.titanium.proxy.TiViewProxy.handleAdd(Unknown Source)\norg.appcelerator.titanium.proxy.TiViewProxy.handleMessage(Unknown Source)\nti.modules.titanium.ui.TableViewProxy.handleMessage(Unknown Source)\nandroid.os.Handler.dispatchMessage(Handler.java:95)\nandroid.os.Looper.loop(Looper.java:123)\nandroid.app.ActivityThread.main(ActivityThread.java:4203)\njava.lang.reflect.Method.invokeNative(Native Method)\njava.lang.reflect.Method.invoke(Method.java:521)\ncom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)\ncom.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)\ndalvik.system.NativeStart.main(Native Method)\n"}
    [TRACE] E/AndroidRuntime( 232): Uncaught handler: thread main exiting due to uncaught exception
    [TRACE] E/AndroidRuntime( 232): java.lang.NullPointerException
    [TRACE] E/AndroidRuntime( 232): at org.appcelerator.titanium.TiProxy.setModelListener(Unknown Source)
    [TRACE] E/AndroidRuntime( 232): at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(Unknown Source)
    [TRACE] E/AndroidRuntime( 232): at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(Unknown Source)
    [TRACE] E/AndroidRuntime( 232): at org.appcelerator.titanium.proxy.TiViewProxy.getView(Unknown Source)
    [TRACE] E/AndroidRuntime( 232): at org.appcelerator.titanium.proxy.TiViewProxy.handleAdd(Unknown Source)
    [TRACE] E/AndroidRuntime( 232): at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(Unknown Source)
    [TRACE] E/AndroidRuntime( 232): at ti.modules.titanium.ui.TableViewProxy.handleMessage(Unknown Source)
    [TRACE] E/AndroidRuntime( 232): at android.os.Handler.dispatchMessage(Handler.java:95)
    [TRACE] E/AndroidRuntime( 232): at android.os.Looper.loop(Looper.java:123)
    [TRACE] E/AndroidRuntime( 232): at android.app.ActivityThread.main(ActivityThread.java:4203)
    [TRACE] E/AndroidRuntime( 232): at java.lang.reflect.Method.invokeNative(Native Method)
    [TRACE] E/AndroidRuntime( 232): at java.lang.reflect.Method.invoke(Method.java:521)
    [TRACE] E/AndroidRuntime( 232): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
    [TRACE] E/AndroidRuntime( 232): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
    [TRACE] E/AndroidRuntime( 232): at dalvik.system.NativeStart.main(Native Method)
    [TRACE] I/Process ( 53): Sending signal. PID: 232 SIG: 3
    [TRACE] I/dalvikvm( 232): threadid=7: reacting to signal 3
    [TRACE] I/dalvikvm( 232): Wrote stack trace to '/data/anr/traces.txt'
    [TRACE] D/dalvikvm( 87): GC freed 12263 objects / 600032 bytes in 294ms
    
    — commented June 3rd 2010 by Markus Birth

3 Answers

  • The problem appears to be caused by the undocumented fact that myTableView.add(myTableViewSection); doesn't work as expected. Rather, you have to add the sections to the data array and then set the tableView's .data property later.

    Here is an example:

    var songListingTable = Titanium.UI.createTableView();
    
    var data = new Array();
    for(albumIndex in window.data.albums){
        var album = window.data.albums[albumIndex];
    
        var tableSection = Ti.UI.createTableViewSection({});
        tableSection.headerTitle = albumName;
    
        for(songIndex in album.songs){
            var song = album.songs[songIndex];
            var songRow = Ti.UI.createTableViewRow({title: song});
            tableSection.add(songRow);
        }
    
        // Add the section here. Will set data value of table later.
        data.push(tableSection);
    }
    songListingTable.data = data;
    

    PS: This seems to be the same problem as http://developer.appcelerator.com/question/74621/tableviewsection-not-creating-sections

    — answered January 22nd 2011 by Sean Colombo
    permalink
    1 Comment
    • Also relevant for null pointer exception when you add rows.

      — commented January 18th 2012 by Anthony Panozzo
  • This may sound dumb, but how do you "Set your Log Level to Trace" … I've been searching up/down/Google for this with no avail.

    — answered September 2nd 2010 by Garrett Wilson
    permalink
    0 Comments
  • it's actually inside the Ti Developer, right next to the dropdown for the SDK, you can choose another dropdown for trace, debug, info, etc.

    rocksteady,
    danno~

    — answered September 2nd 2010 by danno watts
    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.