Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-2853] Android: Creating Button or ImageView Opacity to 1 Causes Null Reference Exception

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2011-11-05T13:58:34.000+0000
Affected Version/sRelease 1.6.0
Fix Version/sSprint 2011-25, Release 1.7.2, Release 1.8.0
ComponentsAndroid
Labelsn/a
ReporterDawson Toth
AssigneeBill Dawson
Created2011-04-15T03:31:11.000+0000
Updated2011-11-05T13:58:34.000+0000

Description

Problem

Creating a Ti.UI.ImageView or a Ti.UI.Button with an opacity of 1 causes a Null Reference Exception to be thrown on Android. An opacity less than 1 works fine, such as 0.5.

This might affect other controls, but I saw it happening on image views and buttons in particular. I believe Ti.UI.View doesn't have this problem (you can create it with an opacity of 1 and it works just fine).

Expected Behavior

No exception should be thrown.

Tested On

Titanium Mobile 1.6.0 (Jan 06 2011)
BROKEN on Android Simulator 2.2
WORKS on iPhone Simulator 4.2

Sample Code

var win = Ti.UI.createWindow({ title: 'Opacity Fail!', backgroundImage: 'default.png' });
win.add(Ti.UI.createImageView({
    image: 'KS_nav_ui.png',
    opacity: 1,
    top: 0, right: 0, left: 0, height: 200
}));
win.add(Ti.UI.createButton({
    title: 'I am a button! Awesome, eh?',
    opacity: 1,
    bottom: 0, right: 0, left: 0, height: 200
}));
win.open();

Trace Log

Attached.

Associated Helpdesk Ticket

http://developer.appcelerator.com/helpdesk/view/61351#c308231">http://developer.appcelerator.com/helpdesk/view/61351#c308231

Attachments

FileDateSize
opacitycrashesandroidlog.rtf2011-04-15T03:31:11.000+000021517

Comments

  1. Andreas sandberg 2011-04-15

    This also affects UILabel elements:

       var win = Ti.UI.createWindow();
        
       var registerLabel = Titanium.UI.createLabel(
       {
           text: 'Stuff in here',
           top:'320dp',
           font: {
               fontSize:'12sp'
           }}
       );
       
       registerLabel.opacity = 0;
       
       var button = Ti.UI.createButton( {
           title: "Login",
           opacity: .2,
           height:'51dp',
           width:'300dp',
           top:'240dp',
           font: {
               fontSize:'20sp', fontWeight:'bold'
           }}
       );
       win.add(button);
       win.add(registerLabel);
       
       button.addEventListener('click', function(){
           registerLabel.opacity = 1;
       });
       
       win.open();
       
  2. Dawson Toth 2011-04-15

    We have enterprise level interest in this now.

    Additional Helpdesk Ticket

    http://developer.appcelerator.com/helpdesk/view/71201">http://developer.appcelerator.com/helpdesk/view/71201

  3. Joe iEntry 2011-04-15

    I can confirm that opacity value of 1 (or 1.0) for image view kills the app on Ti Mobile 1.6.1 and Android 1.6.

    For those looking for a workaround, if it isn't obvious, use 0.99 instead of 1.

  4. Dawson Toth 2011-04-15

    There is additional interest in the fix of this bug: http://support-admin.appcelerator.com/display/QHT-63577-369
  5. Bill Dawson 2011-06-20

    A test app that exercises a few more views/controls:
       Titanium.UI.setBackgroundColor('#000');
       var win = Ti.UI.createWindow({
       	title: 'Opacity Fail!',
       	backgroundImage: 'default.png',
       	exitOnClose: true
       });
       win.add(Ti.UI.createImageView({
       	image: 'KS_nav_ui.png',
       	opacity: 0.8,
       	left: "5dp", width: "50dp", top: "5dp", height: "50dp"
       }));
       win.add(Ti.UI.createImageView({
       	image: 'KS_nav_ui.png',
       	opacity: 1,
       	left: "60dp", width: "50dp", top: "5dp", height: "50dp"
       }));
       
       win.add(Ti.UI.createButton({
       	opacity: 0.8,
       	title: "opacity 0.8",
       	left: "5dp", width: "100dp", top: "70dp", height: "40dp"
       }));
       win.add(Ti.UI.createButton({
       	opacity: 1,
       	title: "opacity 1",
       	left: "110dp", width: "100dp", top: "70dp", height: "40dp"
       }));
       
       win.add(Ti.UI.createLabel({
       	opacity: 0.8,
       	text: "opacity 0.8",
       	color: 'black',
       	backgroundColor: 'green',
       	left: "5dp", width: "100dp", top: "115dp", height: "40dp"
       }));
       win.add(Ti.UI.createLabel({
       	opacity: 1,
       	text: "opacity 1",
       	color: 'black',
       	backgroundColor: 'green',
       	left: "110dp", width: "100dp", top: "115dp", height: "40dp"
       }));
       
       win.add(Ti.UI.createView({
       	opacity: 0.8,
       	backgroundColor: 'green',
       	left: '5dp', width: "100dp", top: "160dp", height: "40dp"
       }));
       win.add(Ti.UI.createView({
       	opacity: 1,
       	backgroundColor: 'green',
       	left: '110dp', width: "100dp", top: "160dp", height: "40dp"
       }));
       
       win.open();
       
  6. Don Thorp 2011-06-23

    merge to 1_7_X
  7. Natalie Huynh 2011-07-06

    Tested with Nexus S 2.3.4 and Nexus One 2.2.2 with 1.7.2.v20110630161836
  8. Don Thorp 2011-11-05

    Standardizing summary and labels.

JSON Source