I'm new at Java and am having a problem that seems simple but I can't figure it out. I am trying to retrieve input from a textfield but when my applet runs it says the value of the text field is NULL. I know this isn't true because: I had previously typed a value into the field, and when the applet was loaded the field was given a intial value rather than being left blank. Finally when I have been trying to solve this problem I have place setText right before my getText command and yet it still says the field is NULL.
Here is the code I used to retrieve the input:
String Value = canField.getText();
Anyone have any ideas?
I have never gotten a null value from a TextField, so this statement:
String s=aTextField.getText().trim() has never thrown a
nullpointerexception, except for the case when aTextField has not been allocated.
It seems there is more to your problem than the statement you have posted;
if canField is not null then it is impossible to get a nullvalue with your statement. A JTextComponent will return null for if the underlying document
is null, but that doesn't apply in your case as far as i can see.
TheTextField documentation says for the getText() method that the
default is an empty string.
You will have to post the whole applet code....
Figured it out, kinda!!
I am useing NetBeans 3.6. When you design the GUI form you have the choice of Swing or AWT objects. I chose AWT TextFields rather than Swing JTextField and it appears that they do not have the same methods because when I replaced my fields with Swign ones it worked fine.
Now I have another question. Netbeans automatically generates the code needed to declare the objects you insert into a form so I think its nto a code problem. What is happending is that when the form starts up some of the objects including textfields and radio buttons are visible. When I click where they shoud be they appear but when I select another object they disappear again. Any thoughts?
It seems like your components are in 'conflict' some way or another. There are a
zillon ways to do something wrong, and why this is happening will just be wild
guesses on my part as long as I have no code to refer to.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center