This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

User Input returns null or an empty string  RSS feed

 
David Jordon
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Below is some of the code I have been working on. At first I tried making a very simple GUI and it worked flawlessly, but that was before I tried making more classes, and now I am very confused and frustrated with what at first had seemed to be the easiest thing to do. I unfortunately deleted my testing code thinking I wouldn't need it anymore, but I do have for you what I have tried so far with my current code. The problem I am facing is that when I create JTextFields and try to use the .getText() method on the them I cannot seem to retrieve the user input. As mentioned earlier this was not a problem with having just one class, but I am assuming it is because I have several classes and some inner classes that I have somewhere confused myself within.

If you look at the primary class here. It creates a form and with a few buttons. I am currently working on get the save button to work. I am trying to use the getText() method to retrieve the users input and store it to a text file once the save button has been clicked. I have been working on this for days now and I just can't seem to get anything else other than an empty line and or "null" to my file/console. So any help at all would be appreciated I am sure there is an easy explanation for this I just can't seem to wrap my head around it though. I didn't want to post to much code here as it may just annoy some if there is a big mess of code, but I am more than willing to post some if you need more to help.

Thanks in advance

 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am more than willing to post some if you need more to help


You need to post a SSCCE that demonstrates your problem.
 
David Jordon
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:
I am more than willing to post some if you need more to help


You need to post a SSCCE that demonstrates your problem.


I was reading some of the SSCCE and I don't really understand what you mean by this. Do you mean I have to have remove some of the code I have in the code I posted, or just post some new code all together? Just so I don't post more code that doesn't help anything.
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What don't you understand? One of the acronyms stands for "Correct/Compileable". Does your code compile.?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In the code you posted, this is the only reference to getText(), which as per description, is returning null or empty string.
Since you have not provided the code for ContactInfoPanel, we cannot possibly download and run your code. This is what Rob means when he says, "Does your code compile"
 
David Jordon
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Sorry about the misunderstanding. I am still new to forums in general, but I added below a working code(except for user input issue) along with this reply. Hopefully I didn't cut too much code out but it has all the essentials that I am talking about that it needs. It compiles and runs anyhow. By the way, it won't allow me to upload my .jar file I made so I don't know where I can upload the actual program that you can just run.

Thanks for your time.

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So when you get an empty string, have you entered anything in the compName text field?
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Above is the line of code that create the ContactInfoPanel that you add to the frame. So any text you enter will be contained in that panel.


The above code does nothing. You just create another panel in memory, but that panel is not visible in the frame. So the code to access the text field returns a null value.

You need to access the text field that was actually added to the frame. The easier way to create all you panels and components in a single class so that you can reference the components from that class.
 
David Jordon
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the help guys I got it now. Rob Camick you pointed out exactly what I needed to see to figure the rest of it out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!