Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-10015

Android: Gradient colors offset property, when unspecified, crashes app

    Details

      Description

      Problem

      If you leave off the offset property of elements in the colors array of a Gradient, the app crashes.

      Expected behavior

      First element of the colors array should default to offset:0.0, and the second element of the colors array should default to offset:1.0, as this is a common case (full width or height gradient). Alternatively, a console error or "red & white error screen" should be produced when the offset property is not specified.

      Actual bahavior

      A "force close" occurs with this crash error in the console log:

      console log

      [ERROR][TiApplication(  526)] (main) [104,104] Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eCotton.GradientTest/org.appcelerator.titanium.TiActivity}: java.lang.NullPointerException; Titanium 2.1.0,2012/06/28 12:16,6e3cab6
      [ERROR][TiApplication(  526)] java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eCotton.GradientTest/org.appcelerator.titanium.TiActivity}: java.lang.NullPointerException
      [ERROR][TiApplication(  526)] 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
      [ERROR][TiApplication(  526)] 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
      [ERROR][TiApplication(  526)] 	at android.app.ActivityThread.access$2300(ActivityThread.java:125)
      [ERROR][TiApplication(  526)] 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
      [ERROR][TiApplication(  526)] 	at android.os.Handler.dispatchMessage(Handler.java:99)
      [ERROR][TiApplication(  526)] 	at android.os.Looper.loop(Looper.java:123)
      [ERROR][TiApplication(  526)] 	at android.app.ActivityThread.main(ActivityThread.java:4627)
      [ERROR][TiApplication(  526)] 	at java.lang.reflect.Method.invokeNative(Native Method)
      [ERROR][TiApplication(  526)] 	at java.lang.reflect.Method.invoke(Method.java:521)
      [ERROR][TiApplication(  526)] 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
      [ERROR][TiApplication(  526)] 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
      [ERROR][TiApplication(  526)] 	at dalvik.system.NativeStart.main(Native Method)
      [ERROR][TiApplication(  526)] Caused by: java.lang.NullPointerException
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.util.TiConvert.toFloat(TiConvert.java:432)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.util.TiConvert.toFloat(TiConvert.java:462)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.view.TiGradientDrawable.loadColors(TiGradientDrawable.java:106)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.view.TiGradientDrawable.<init>(TiGradientDrawable.java:83)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.view.TiUIView.handleBackgroundImage(TiUIView.java:824)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.view.TiUIView.processProperties(TiUIView.java:594)
      [ERROR][TiApplication(  526)] 	at ti.modules.titanium.ui.widget.TiView.processProperties(TiView.java:49)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:884)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:441)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:433)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:411)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.proxy.TiViewProxy.handleAdd(TiViewProxy.java:527)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:204)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.proxy.TiWindowProxy.handleMessage(TiWindowProxy.java:111)
      [ERROR][TiApplication(  526)] 	at ti.modules.titanium.ui.ActivityWindowProxy.handleMessage(ActivityWindowProxy.java:93)
      [ERROR][TiApplication(  526)] 	at android.os.Handler.dispatchMessage(Handler.java:95)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.kroll.common.TiMessenger.dispatchMessage(TiMessenger.java:365)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.kroll.common.TiMessenger.dispatchPendingMessages(TiMessenger.java:350)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.kroll.common.TiMessenger$2.getResult(TiMessenger.java:235)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.kroll.common.TiMessenger.sendBlockingMessage(TiMessenger.java:262)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.kroll.common.TiMessenger.sendBlockingRuntimeMessage(TiMessenger.java:187)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.kroll.KrollProxy.fireSyncEvent(KrollProxy.java:605)
      [ERROR][TiApplication(  526)] 	at ti.modules.titanium.ui.TiUIActivityWindow.windowCreated(TiUIActivityWindow.java:142)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.TiActivityWindows.windowCreated(TiActivityWindows.java:31)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.TiBaseActivity.windowCreated(TiBaseActivity.java:352)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:425)
      [ERROR][TiApplication(  526)] 	at org.appcelerator.titanium.TiActivity.onCreate(TiActivity.java:22)
      [ERROR][TiApplication(  526)] 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
      [ERROR][TiApplication(  526)] 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
      [ERROR][TiApplication(  526)] 	... 11 more
      [ERROR][AndroidRuntime(  526)] FATAL EXCEPTION: main
      [ERROR][AndroidRuntime(  526)] java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eCotton.GradientTest/org.appcelerator.titanium.TiActivity}: java.lang.NullPointerException
      [ERROR][AndroidRuntime(  526)] 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
      [ERROR][AndroidRuntime(  526)] 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
      [ERROR][AndroidRuntime(  526)] 	at android.app.ActivityThread.access$2300(ActivityThread.java:125)
      [ERROR][AndroidRuntime(  526)] 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
      [ERROR][AndroidRuntime(  526)] 	at android.os.Handler.dispatchMessage(Handler.java:99)
      [ERROR][AndroidRuntime(  526)] 	at android.os.Looper.loop(Looper.java:123)
      [ERROR][AndroidRuntime(  526)] 	at android.app.ActivityThread.main(ActivityThread.java:4627)
      [ERROR][AndroidRuntime(  526)] 	at java.lang.reflect.Method.invokeNative(Native Method)
      [ERROR][AndroidRuntime(  526)] 	at java.lang.reflect.Method.invoke(Method.java:521)
      [ERROR][AndroidRuntime(  526)] 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
      [ERROR][AndroidRuntime(  526)] 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
      [ERROR][AndroidRuntime(  526)] 	at dalvik.system.NativeStart.main(Native Method)
      [ERROR][AndroidRuntime(  526)] Caused by: java.lang.NullPointerException
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.util.TiConvert.toFloat(TiConvert.java:432)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.util.TiConvert.toFloat(TiConvert.java:462)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.view.TiGradientDrawable.loadColors(TiGradientDrawable.java:106)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.view.TiGradientDrawable.<init>(TiGradientDrawable.java:83)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.view.TiUIView.handleBackgroundImage(TiUIView.java:824)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.view.TiUIView.processProperties(TiUIView.java:594)
      [ERROR][AndroidRuntime(  526)] 	at ti.modules.titanium.ui.widget.TiView.processProperties(TiView.java:49)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:884)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:441)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:433)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:411)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.proxy.TiViewProxy.handleAdd(TiViewProxy.java:527)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:204)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.proxy.TiWindowProxy.handleMessage(TiWindowProxy.java:111)
      [ERROR][AndroidRuntime(  526)] 	at ti.modules.titanium.ui.ActivityWindowProxy.handleMessage(ActivityWindowProxy.java:93)
      [ERROR][AndroidRuntime(  526)] 	at android.os.Handler.dispatchMessage(Handler.java:95)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.kroll.common.TiMessenger.dispatchMessage(TiMessenger.java:365)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.kroll.common.TiMessenger.dispatchPendingMessages(TiMessenger.java:350)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.kroll.common.TiMessenger$2.getResult(TiMessenger.java:235)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.kroll.common.TiMessenger.sendBlockingMessage(TiMessenger.java:262)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.kroll.common.TiMessenger.sendBlockingRuntimeMessage(TiMessenger.java:187)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.kroll.KrollProxy.fireSyncEvent(KrollProxy.java:605)
      [ERROR][AndroidRuntime(  526)] 	at ti.modules.titanium.ui.TiUIActivityWindow.windowCreated(TiUIActivityWindow.java:142)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.TiActivityWindows.windowCreated(TiActivityWindows.java:31)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.TiBaseActivity.windowCreated(TiBaseActivity.java:352)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:425)
      [ERROR][AndroidRuntime(  526)] 	at org.appcelerator.titanium.TiActivity.onCreate(TiActivity.java:22)
      [ERROR][AndroidRuntime(  526)] 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
      [ERROR][AndroidRuntime(  526)] 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
      [ERROR][AndroidRuntime(  526)] 	... 11 more
      [WARN][ActivityManager(   60)]   Force finishing activity com.eCotton.GradientTest/org.appcelerator.titanium.TiActivity
      

      Testcase

      Run the following code. A white-to-red vertical gradient box should appear at the top of the screen, but instead the app crashes.

      Now uncomment the offset code. The box appears with the correct gradient.

      app.js

      var win1=Ti.UI.createWindow({
                       layout:'vertical',
                       backgroundColor:'gray',
                       exitOnClose:true,
                       navBarHidden:true
                     });
       
      var view1=Ti.UI.createView({
                        height:100,
                        width:100,
                        backgroundGradient:{type:'linear',
                                            endPoint:{ x:0, y:'100%' },
                                            colors:[ {color:'white' /*, offset:0.0*/ },
                                                     {color:'red' /*, offset:1.0*/ } ]}
                      });
      win1.add(view1);
       
      win1.open();
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                joshroesslein Josh Roesslein
                Reporter:
                bitshftr Shawn Lipscomb
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-5419
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Integration