Titanium Community Questions & Answer Archive

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

substring(0,1) not working on ANDROID...

this is not working on ANDROID:
var h2LNAME = 'ZZ';
h2LNAME = h2LNAME.substring(0,1);

whats the matter with it.. there is a runtime error. Type error: cannot call method "substring" of null…
but works on iPHNONE

— asked November 20th 2010 by vincent youmans
  • android
  • substring
0 Comments

3 Answers

  • Accepted Answer

    Hi Vincent

    It returns OK for me on Android SDK 2.2, Titanium SDK 1.4.X, using the following code:

    var win = Ti.UI.createWindow({
        backgroundColor:'red',
        exitOnClose:true,
        layout:'vertical'
    });
    
    var h2LNAME = 'ZZ';
    h2LNAME = h2LNAME.substring(0,1);
    
    var label = Ti.UI.createLabel({
        backgroundColor:'blue',
        color:'white',
        text:'substring returns : '+h2LNAME,
        textAlign:'center',
        top:10,
        height:60,
        width:200
    });
    
    win.add(label);
    
    win.open();
    

    See this screenshot

    — answered November 20th 2010 by Paul Dowsett
    permalink
    0 Comments
  • substring is not working with text field value
    Plz help me out…

    var txtVal= parseInt(txtC61.value)
    var resultC6= txtVal + 1234;
    resultC6= resultC6.substring(0,2)
    Label6.text='Value is '+ resultC6;
    }

    — answered April 2nd 2013 by Asfandyar Barki
    permalink
    0 Comments
  • I took the same code, and put it in a new project.. and now it works…
    don't know what to say. But its working for me now as well.

    — answered November 21st 2010 by vincent youmans
    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.