java.lang.NumberFormatException: For input string: ""

Hi.

I am new to this forum.I have not so much idea in java swing.I am doing an application in java swing.I used a JTextField.In side a loop I have written as below

if(!(txt_pageNo.getText() == ""))

{

System.out.println("coming in textfield..... 998");

if((Integer.parseInt(txt_pageNo.getText()) > commTotPage) || Integer.parseInt(txt_pageNo.getText()) <= 0)

{

}else

if((Integer.parseInt(txt_pageNo.getText()) != currentCommPage))

{

commTableDisplayOptionNo = 0;

currentCommPage = Integer.parseInt(txt_pageNo.getText());

comTabDispName = "MyVaayooPoker Communities" ;

Thread tt = new Thread()

{

public void run()

{

try

{

displayContrrol = 1;

String request = "reqid=01,appid=smruti,alphabet=all,commBulkNo="+currentCommPage;

httpTest.sendRequest(request);

//System.out.println("controller will come here");

}

catch(Exception e)

{

System.out.println("in sending requsst2..");

}

}

};

tt.start();

}

I have set initial text = " ";

When I left the field blank it still enters in side the if(!(txt_pageNo.getText() == "")) and giving me java.lang.NumberFormatException: For input string: "" error.

Thanks.

Srikant

[1330 byte] By [srikanta] at [2007-10-2 12:41:22]
# 1

if(!(txt_pageNo.getText() == ""))

When comparing Strings, you should use the .equals() method. But in this case if you are checking for an empty String, you could also use the following, which is clearer code in some people's opinionif(txt_pageNo.getText().length() == 0)

Also, your post says I have set initial text = " ";Note that there is a space between the "" which makes it not equal to "". If you have a String which might contain non-numeric characters, you can put the Integer.parseInt() method inside a try/catch block and catch the number format exception or have a calling method catch it and react accordingly.

atmguya at 2007-7-13 9:46:27 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
Thanks atmguy this was a silly mistake of mine.Thanks again
srikanta at 2007-7-13 9:46:27 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...