This is my code:

package hello;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author User
 */
public class TBexample extends MIDlet
{
    Display display;
    public static String txt;
    TextBox sample;
    public TBexample()
    {
        txt  = "enter your text here";

    }
    public void startApp() 
    {

       // String localtext ="hi";
         display = Display.getDisplay(this);
         sample = new TextBox("play","",16,TextField.ANY);
        //sample.insert(localtext,0);
        sample.setString(txt);
        display.setCurrent(sample);

    }

    public void pauseApp() {
        txt = sample.getString();
    }

    public void destroyApp(boolean unconditional) {
    }
}
****************************************************

i am getting a illegal argment Ecxeption for calling sample.SetString(txt).bt instead txt(class variable) of that if i use a local variable that works fine.Can anyone tell why?

Maybe because your txt value exceeds the 16 char max size that you set for the text box?

no if that commented insert is working fine.problem is only when i use the class ariable txt.

Looks to me like the local var is 2 chars vs ~20 for the static value?

I played around with your code and there is strange behaviour that I'm little baffled. I think that maybe somebody with depth knowledge of Java would be able to explain.
From your short code it is not clear why ever would you like to change text inside TextBox (I never need it to do so because of following). Under normal circumstances you will either pass text directly to TextBox constructor to be showed on the screen or collect text from this class. This class is normally placed on screen only accompanied by commands and does not really work in the same fashion as you may know TextArea or JTextArea in JSE that you collect data from one place and drop them in TextArea that is part taking in the GUI form. I think TextBox.setString(String) method will be deprecated with new release of Java Microedition.
So if you want to place any text into TextBox you need to do it in constructor TextBox(String title, String text, int maxSize, int constraints)

@Above
i am a begginner in j2me.so was just trying to figure out how all these things work.
thanks for your reply.

You welcome.
If you new to J2ME you may want to have look at this post here, that is specifically dealing with basics of J2ME in terms what you may need, where you want to look etc. Plus I made blog entry on How-To custom WTK NetBeans and IntelliJ IDEA that explains where to find and how to add Sony Ericsson, Nokia or others WirelessToolKits to NetBeans or IntelliJ IDEA.

PS: If your original question been solved, please kindly marked this post as solved by clicking on "Mark as Solved" below last post. Thank you

thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.