The Artima Developer Community
Sponsored Link

Java Answers Forum
String problem

5 replies on 1 page. Most recent reply: Oct 22, 2003 1:55 AM by KevinT

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Pratheeba

Posts: 11
Nickname: pratheeba
Registered: Sep, 2003

String problem Posted: Oct 17, 2003 10:26 AM
Reply to this message Reply
Advertisement
Hi,

I am trying to get value from JTextField.I stored that string into a string named textname.My problem is if i didn't enter anything in the JtextField, the string textname is not having any thing...That's even a null value...

ie. String textname = txt.getText();
System.out.println("Name is " + textname);

It gives output as follows:

Name is




I am checking some condition if it is null like that...for that i gave

if (textname == null)
{
System.out.println(" Please enter something");
}


But it's not working...I am surprised why it's not working...Is that am i doing wrong????
Give me solution please ....it's urgent


Clay Dagler

Posts: 21
Nickname: cdagler
Registered: Jul, 2003

Re: String problem Posted: Oct 17, 2003 10:33 AM
Reply to this message Reply
> Hi,
>
> I am trying to get value from JTextField.I stored that
> string into a string named textname.My problem is if i
> didn't enter anything in the JtextField, the string
> textname is not having any thing...That's even a null
> value...
>
> ie. String textname = txt.getText();
> System.out.println("Name is " + textname);
>
> It gives output as follows:
>
> Name is
>
>
>
>
> I am checking some condition if it is null like that...for
> that i gave
>
> if (textname == null)
> {
> System.out.println(" Please enter something");
> }
>
>
> But it's not working...I am surprised why it's not
> working...Is that am i doing wrong????
> Give me solution please ....it's urgent

Try

if (textname == "")
{
System.out.println(" Please enter something");
}

I am 95% sure that this will work.

Clay

Pratheeba

Posts: 11
Nickname: pratheeba
Registered: Sep, 2003

Re: String problem Posted: Oct 17, 2003 10:40 AM
Reply to this message Reply
I tried, i am sorry ...it's not working...

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: String problem Posted: Oct 17, 2003 1:43 PM
Reply to this message Reply
textname.equals("");

katta kishore

Posts: 2
Nickname: kake
Registered: Oct, 2003

Re: String problem Posted: Oct 20, 2003 5:24 AM
Reply to this message Reply
yes it works

KevinT

Posts: 24
Nickname: metzedler
Registered: Jun, 2003

Re: String problem Posted: Oct 22, 2003 1:55 AM
Reply to this message Reply
I think there is another way which makes it works:

if (textname.length() == 0)
{
System.out.println(" Please enter something");
}

Flat View: This topic has 5 replies on 1 page
Topic: JList problem HELP! Previous Topic   Next Topic Topic: Help me better Understand?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use