×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    29

    dynamic creation of textfield

    hi..
    how to create dynamic textfields based on selection of choicegroup and retrieve values from textfields in j2me.
    thanks and regards..
    reshmy

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: dynamic creation of textfield

    Hi Reshmy,

    ChoiceGroups have methods to retrieve their state, like getSelectedFlags() and isSelected(int elementNum). Using these methods, you can easily initialize your TextFields with a dynamic value based on ChoiceGroup state.

    About TextFields, you can use getString() method to retrieve the field current value.

    Pit

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    29

    Re: dynamic creation of textfield

    hi..
    d code is below.its showing "null pointer exception".can u explain that more clearly.
    <code>
    for (int i = 0; i<cg.size(); i++)
    {
    if (cg.isSelected(i))
    {


    b.append(cg.getString(i));
    //#style mainCommand

    /** textField2= new TextField(new String(b)+" ","1",2,TextField.NUMERIC);
    String st = textField2.getString();
    System.out.println(st);
    //#style mainCommand
    order.append(textField2);*/
    textFieldrr[i]= new TextField(new String(b)+" ","1",2,TextField.NUMERIC);
    order.append(textFieldrr[i]);
    String st = textFieldrr[i].getString();
    System.out.println(st);
    b.append("\n");
    b=null;

    b = new StringBuffer();
    }
    </code>
    thanks

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: dynamic creation of textfield

    Do you inizialize your StringBuffer b somewhere before the for loop? Otherwise, the first append operation "b.append(cg.getString(i));" will raise your NullPointer exception.

    Anyway, you could try do some debugging, checking whick object is null.

    Pit

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    29

    Re: dynamic creation of textfield

    hi..ya.i initialised d string buffer.pls check it.

    public Form order()
    {
    order=null;
    if(order==null)
    {
    //#ifdef title:defined
    //#= String title = "${ title }";
    //#else
    String title = "6ALABAT";
    //#endif
    //#style mainScreen
    order=new Form(title);

    //#style mainCommand
    order.append("Please insert the quantity");
    //order.addCommand(orderCommand);
    //order.addCommand(backsectionCommand);
    order.addCommand(backfrmqtyCommand);
    order.addCommand(doneCommand);
    // order.addCommand(exitCommand);
    order.setCommandListener(this);
    StringBuffer b = new StringBuffer();
    // int j=cg.getSelectedFlags(boolean[] selectesArray_return);
    for (int i = 0; i<cg.size(); i++)
    {
    if (cg.isSelected(i))
    {


    b.append(cg.getString(i));
    //#style mainCommand

    /** textField2= new TextField(new String(b)+" ","1",2,TextField.NUMERIC);
    String st = textField2.getString();
    System.out.println(st);
    //#style mainCommand
    order.append(textField2);*/
    textFieldrr[i]= new TextField(new String(b)+" ","1",2,TextField.NUMERIC);
    order.append(textFieldrr[i]);
    String st = textFieldrr[i].getString();
    System.out.println(st);
    b.append("\n");
    b=null;

    b = new StringBuffer();
    }
    /** if(cg.isSelected(i))
    {
    b.append(cg.getString(i));

    tf1[i]=new TextField(new String(b)+" ","1",2,TextField.NUMERIC);
    order.append(tf1[i]);
    String st = tf1[i].getString();
    System.out.println(st);
    b.append("\n");
    b=null;

    b = new StringBuffer();

    }*/

    }

    }
    return order;
    }


    thanks for ur quick response..

  6. #6
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: dynamic creation of textfield

    In your code there are 4 objects that are not inizialized within the order() method (they could be inizialized somewhere else, but it's not possible to say it from the code you posted): they're cg, textFieldrr and the 2 commands that you add, that if null could raise the NullPointer exception.

    Anyway, even with a simple printStackTrace of your NullPointer exception you should be able to find out the cause.

    Pit

  7. #7
    Registered User
    Join Date
    Mar 2008
    Posts
    29

    Re: dynamic creation of textfield

    hi..
    this is d error.wht should i do?

    java.lang.NullPointerException
    Nokia/Midp2Cldc11: at de.enough.polish.example.MainMidlet.order(+175)
    Unable to translate stacktrace: Unable to start the "jad"-decompiler: [java.io.IOException: Cannot run program "jad.exe": CreateProcess error=2, The system cannot find the file specified]. jad is available from http://www.kpdus.com/jad.html.
    Nokia/Midp2Cldc11: at de.enough.polish.example.MainMidlet.commandAction(+831)
    Nokia/Midp2Cldc11: at de.enough.polish.ui.Screen$ForwardCommandListener.commandAction(+146)
    Nokia/Midp2Cldc11: at de.enough.polish.ui.Screen.callCommandListener(+21)
    Nokia/Midp2Cldc11: at de.enough.polish.ui.CommandItem.handleKeyPressed(+141)
    Nokia/Midp2Cldc11: at de.enough.polish.ui.Container.handleKeyPressed(+30)
    Nokia/Midp2Cldc11: at de.enough.polish.ui.Screen.keyPressed(+276)
    Nokia/Midp2Cldc11: at javax.microedition.lcdui.Canvas.callKeyPressed(+19)
    Nokia/Midp2Cldc11: at javax.microedition.lcdui.Display$DisplayAccessor.keyEvent(+198)
    Nokia/Midp2Cldc11: at javax.microedition.lcdui.Display$DisplayManagerImpl.keyEvent(+11)
    Nokia/Midp2Cldc11: at com.sun.midp.lcdui.DefaultEventHandler.keyEvent(+121)
    Nokia/Midp2Cldc11: at com.sun.midp.lcdui.AutomatedEventHandler.keyEvent(+210)
    Nokia/Midp2Cldc11: at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+178)

Similar Threads

  1. Dynamic Creation of tabs
    By harleen_bhatia in forum Symbian User Interface
    Replies: 7
    Last Post: 2008-08-05, 06:57
  2. dynamic UI creation
    By tomsoft in forum Symbian User Interface
    Replies: 7
    Last Post: 2007-03-09, 04:47
  3. Dynamic Sub Menu creation
    By Blkangel in forum Symbian User Interface
    Replies: 4
    Last Post: 2005-08-08, 04:14
  4. CAknListQueryDialog dynamic creation
    By shocy in forum Symbian User Interface
    Replies: 0
    Last Post: 2004-05-18, 21:20
  5. Replies: 0
    Last Post: 2002-06-11, 08:52

Posting Permissions

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