Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Basic GUI problem  :( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Basic GUI problem  :(" Watch "Basic GUI problem  :(" New topic
Author

Basic GUI problem :(

Waria Ahmed
Ranch Hand

Joined: Jul 09, 2008
Posts: 56
Just creating a test GUI program, I have got a text field for first name and a text field for last name. In my JFrame class I am trying to take the input from firstNameTextField and in return print out the last name into the lastNameTextField. This is my code for the actionPerformed�



Basically if the text in the firstText ( variable name for my textfield) matches the first name of the person in the array. Then I want to print the second name in the text field. However I am having problems getting the text from first text field.

Can anyone shed any light on this matter please? Am I doing anything wrong?

Thanks
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

Did you create a method "firstTextequals" or is there supposed to be a dot in there somewhere? Please be careful to Post Real Code.
Assuming that you wanted to write "firstText.equals", exactly what are you comparing to the values in the array?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Waria Ahmed
Ranch Hand

Joined: Jul 09, 2008
Posts: 56
Yes i missed a . there but it still doesnt work.

Basically "firstText" is the variable name for the textfield, which the user types into. And whenever the user presses the search button, I want the program to take what the user typed into "firstText" and search through the array looking to see if it matches any people in array.

If it matches, I want the second name of the person to be displayed in "lastText" textfield.

I know my explanation isnt the best, so please feel free to ask further questions.

Thanks
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

Originally posted by Waria Ahmed:

Basically "firstText" is the variable name for the textfield,


OK. So you have a textfield named "firstText". In the following comparison, what is being compared:


Hint: what is the type of firstText? What does the array contain? Can they ever be equal?
Waria Ahmed
Ranch Hand

Joined: Jul 09, 2008
Posts: 56
Im assuming the firstText is a String, and getFirstName returns a String?

i get the NullPointerException when i run the program.
Waria Ahmed
Ranch Hand

Joined: Jul 09, 2008
Posts: 56
This is the full program if it helps...



And Person class...

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

Originally posted by Waria Ahmed:
Im assuming the firstText is a String, and getFirstName returns a String?


Your assumption is wrong. Your code says:
Waria Ahmed
Ranch Hand

Joined: Jul 09, 2008
Posts: 56
OHHHH Ok.... I get you.

How do I store the input from user as firstText?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

It should be in there if the user has typed something in.
It is a good idea to print out the values you are comparing when things aren't working the way you think they should.
Waria Ahmed
Ranch Hand

Joined: Jul 09, 2008
Posts: 56
This is the error I get when i type something and press "search"

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at uni.NewJFrame.searchButtonActionPerformed(NewJFrame.java:104)
at uni.NewJFrame.access$100(NewJFrame.java:16)
at uni.NewJFrame$2.actionPerformed(NewJFrame.java:53)
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

It is a good idea to print out the values you are comparing when things aren't working the way you think they should.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Basic GUI problem :(
 
Similar Threads
Printing a HashSet that contains arrays of Strings
GUI runtime error
What do you think on these two things?
GUI Help please
DateFormatSymbols's getMonths() returns 13 values