×

Discussion Board

Results 1 to 2 of 2

Thread: textfield[]

  1. #1
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    77

    textfield[]

    I want to add the textfields dynamically
    so

    if(item == choiceGroup)
    {
    // BillPayment.deleteAll();
    RecordStore rs =null;
    try{
    rs = RecordStore.openRecordStore("BillStore",true);
    String[] s1 = new String[rs.getNumRecords()];
    String[] s2 = null;
    byte[] recData;
    String FLAGSTRING,s;
    for (int i = 1; i <= rs.getNumRecords(); i++)
    {
    recData = new byte[rs.getRecordSize(i)];
    int length = rs.getRecord(i,recData,0);
    FLAGSTRING = new String(recData,0,length);
    s = FLAGSTRING.substring(0,FLAGSTRING.length());

    String bill_type = s.substring(0,s.indexOf('='));//billname

    //RoutEquNO%varchar%20,RoutQty1%int%10,RobEquiNO%varchar%20,RobQty%int%10
    String r_data = s.substring(s.indexOf('=')+1, s.length());
    int spl_fld = splitData(r_data, ',', 0);//splits the data


    for(int j = 0; j <= spl_fld; j++)
    {
    //RoutEquNO%varchar%20
    comp_data = con_str[j];
    String text_name = con_str[j].substring(0, con_str[j].indexOf('%'));
    String type = con_str[j].substring(con_str[j].indexOf('%')+1, con_str[j].lastIndexOf('%'));
    int size = Integer.parseInt(con_str[j].substring(con_str[j].lastIndexOf('%')+1, con_str[j].length()));
    System.out.println(text_name+","+type+","+size);
    if(type.equalsIgnoreCase("varchar"))
    {
    dtype = TextField.ANY;
    //textField = new TextField("Merchant Key", null, 32, TextField.ANY);
    tf[j] = new TextField(text_name, "", size, dtype);
    // tf = new TextField(text_name, "", size, dtype);

    //BillPayment.append(tf[j]);
    }else if(type.equalsIgnoreCase("int")){
    dtype = TextField.NUMERIC;
    tf[j] = new TextField(text_name, "", size, dtype);
    // BillPayment.append(tf[j]);
    }
    BillPayment.append(tf[j]);
    }


    but here im getting NullPointer Exception...when using normal tf the textfields are added but when i want to get data from respected fields then how to call i.e tf.getString() since that is in loop it is added but the same textfield tf used for all.......

    Please anyone help me....

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: textfield[]

    Do you know where you get the NullPointerException? Finding out would really help you...

    Oh, beware of equalsIgnoreCase()... it only works on devices with CLDC-1.1, not 1.0, so you might your code breaks on some older devices.

    Graham.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×