Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20262] Android: exception when borderColor is modified without setting first in the constructor

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 5.1.2
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, javascript
ReporterÁngel Flores
AssigneeUnknown
Created2016-01-19T09:30:09.000+0000
Updated2018-02-28T19:55:28.000+0000

Description

I want to mark a row of a table as selected using a border. Given that the border does not work at all if it is set in the tableViewRow, I tried it using an inner view. If I try to modify the color of the view border without setting first in the constructor, an exception is thrown.
var table = Ti.UI.createTableView({id:"table", top:10, width:Ti.UI.FILL, height:Ti.UI.SIZE, backgroundColor: Config.BACKGROUND_COLOR_LIST, scrollable:true, separatorColor:"white", title: {font:{fontWeight:'bold'}}});
	var row = Ti.UI.createTableViewRow({id: Math.random(), width:Ti.UI.FILL, height:Ti.UI.SIZE, layout: "horizontal", backgroundFocusedColor: Config.MAIN_COLOR, chosen:false});
            var borderView=Ti.UI.createView({width:Ti.UI.SIZE, height:Ti.UI.SIZE, layout: "horizontal", /*borderColor:Config.BUTTON_COLOR, */borderWidth:0});
                var logo = Ti.UI.createImageView({width:"20%", height:Ti.UI.SIZE, image: '/appicon.png', defaultImage: '/appicon.png'});
                var content= Ti.UI.createView({width:"80%", height:Ti.UI.SIZE});
				...
				...
				...
row.addEventListener("click", rowClickEvent(row.id));


function rowClickEvent(rowId)
{
    return function()
    {
        var dataRows = table.data[0].rows;
        
        for(i=0;i<dataRows.length;i++)
        {
            var item = dataRows[i];
            var borderView = item.children[0];
            
            if(rowId == item.id)
            {
                item.chosen= !item.chosen;
                
                button.disabled = !item.chosen;
                if(item.chosen)
                {
                    Ti.API.info("Selecting the row...");
                    borderView.borderColor=Config.BUTTON_COLOR;//<-----it throws an exception
                    borderView.borderWidth = '5dp';
                }
                else
                {
                    Ti.API.info("Unselecting the row...");
                    borderView.borderColor=Config.BACKGROUND_COLOR_LIST;//<-----it throws an exception
                    borderView.borderWidth = 0;
                }
            }
            else if(item.chosen && (rowId != item.id))//avoid the blink
            {
                Ti.API.info("Unselecting the row...");
                borderView.borderColor = Config.BACKGROUND_COLOR_LIST;//<-----it throws an exception
                borderView.borderWidth = 0;
                item.chosen=false;
            }
        }
    };
}

[ERROR] :  TiApplication: (main) [12903,12903] Sending event: exception on thread: main msg:java.lang.NullPointerException: Attempt to invoke virtual method 'void org.appcelerator.titanium.view.TiBorderWrapperView.setColor(int)' on a null object reference; Titanium 4.0.0,2015/05/18 15:42,9239ff9
[ERROR] :  TiApplication: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.appcelerator.titanium.view.TiBorderWrapperView.setColor(int)' on a null object reference
[ERROR] :  TiApplication: 	at org.appcelerator.titanium.view.TiUIView.handleBorderProperty(TiUIView.java:1269)
[ERROR] :  TiApplication: 	at org.appcelerator.titanium.view.TiUIView.propertyChanged(TiUIView.java:842)
[ERROR] :  TiApplication: 	at org.appcelerator.kroll.KrollPropertyChange.fireEvent(KrollPropertyChange.java:21)
[ERROR] :  TiApplication: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1083)
[ERROR] :  TiApplication: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:347)
[ERROR] :  TiApplication: 	at android.os.Handler.dispatchMessage(Handler.java:98)
[ERROR] :  TiApplication: 	at android.os.Looper.loop(Looper.java:135)
[ERROR] :  TiApplication: 	at android.app.ActivityThread.main(ActivityThread.java:5538)
[ERROR] :  TiApplication: 	at java.lang.reflect.Method.invoke(Native Method)
[ERROR] :  TiApplication: 	at java.lang.reflect.Method.invoke(Method.java:372)
[ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
[ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

Comments

  1. Sharif AbuDarda 2016-01-20

    Hello, I was testing this issue. I find out the same problem when I tried to put a border color in the view of the selected table row when the row is clicked. I am testing the below code.
       var tableData = [];
       
       var win = Ti.UI.createWindow({ backgroundColor: 'white' });
       
       var table = Ti.UI.createTableView({ objName: 'table' });
       
       for (var i = 0; i <= 20; i++){
         var row = Ti.UI.createTableViewRow({
           className: 'row',
           objName: 'row',
           touchEnabled: true,
           height: 100
         });
       
         var enabledWrapperView = Ti.UI.createView({
           backgroundColor:'#008FD5',
           objName: 'enabledWrapperView',
           rowID: i,
           width: Ti.UI.FILL, height: '100%',
           
         });
       
       
         var label = Ti.UI.createLabel({
           backgroundColor:'#313F48',
           color: 'white',
           objName: 'label',
           text: i,
           touchEnabled: false,
           left: 0,
           width: 200
         });
         enabledWrapperView.add(label);
       
         row.add(enabledWrapperView);
         tableData.push(row);
       }
       
       table.setData(tableData);
       
       table.addEventListener('click', function(e){
         if (e.source && e.source.objName !== 'table'){
           
           e.source.borderColor = 'green';
           e.source.borderWidth = 5;
           Ti.API.info('Row Click: ' + e.source.objName);
           Ti.API.info('Row ID : ' + e.source.rowID);
         }
       });
       
       win.add(table);
       win.open();
       
    The below error occue
       [ERROR] :  TiApplication: (main) [8028,14406] Sending event: exception on thread: main msg:java.lang.NullPointerException: Attempt to invoke virtual method 'void org.appcelerator.titanium.view.TiBorderWrapperView.setColor(int)' on a null object reference; Titanium 5.1.2,2015/12/16 19:00,ca822b2
       [ERROR] :  TiApplication: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.appcelerator.titanium.view.TiBorderWrapperView.setColor(int)' on a null object reference
       [ERROR] :  TiApplication: 	at org.appcelerator.titanium.view.TiUIView.handleBorderProperty(TiUIView.java:1302)
       [ERROR] :  TiApplication: 	at org.appcelerator.titanium.view.TiUIView.propertyChanged(TiUIView.java:843)
       [ERROR] :  TiApplication: 	at org.appcelerator.kroll.KrollPropertyChange.fireEvent(KrollPropertyChange.java:21)
       [ERROR] :  TiApplication: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1083)
       [ERROR] :  TiApplication: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:352)
       [ERROR] :  TiApplication: 	at android.os.Handler.dispatchMessage(Handler.java:98)
       [ERROR] :  TiApplication: 	at android.os.Looper.loop(Looper.java:135)
       [ERROR] :  TiApplication: 	at android.app.ActivityThread.main(ActivityThread.java:5254)
       [ERROR] :  TiApplication: 	at java.lang.reflect.Method.invoke(Native Method)
       [ERROR] :  TiApplication: 	at java.lang.reflect.Method.invoke(Method.java:372)
       [ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
       [ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
       

    Environment

    CLI 5.1.0 SDK 5.1.2.GA Android 5.1.0

    Expected result

    View of the selected table row should show border color. Thanks.

JSON Source