Ed fields return NULL problem !
My text fields when I put input in them is returning NULL ?!
Here is a sample code:
private void jEdFeild1(java.awt.event.ActionEvent evt) {
myAns=jEdFeild.getSelectedText();
}
The variable myAns will return the string when in the method but not where I want it which is in another
method called:
private void writeit(java.awt.event.ActionEvent evt) {
....
System.out.printf("ans= %s",myans);
:confused:
}
Re: Ed fields return NULL problem !
An object reference variable will have a null value until it is assigned a value.
Are you sure the variable is being assigned a value before the code looks at the contents of the variable?
Add a print statement after the assignment statement to show when it is being executed.
Please wrap all posted code in code tags to get highlighting and preserve formatting.
Re: Ed fields return NULL problem !
Quote:
Originally Posted by
Norm
An object reference variable will have a null value until it is assigned a value.
Are you sure the variable is being assigned a value before the code looks at the contents of the variable?
Add a print statement after the assignment statement to show when it is being executed.
Please wrap all posted code in code tags to get highlighting and preserve formatting.
The
Code:
System.out.println()
is the print statement I use to it out. I find out by hitting return after typing the fields get assigned a value. Is there any way the field can be assigned while being typed?
Re: Ed fields return NULL problem !
Quote:
Is there any way the field can be assigned while being typed?
Where is the value that you want assigned to the variable? If the value is being entered by a user, can the user tell the program when the value is ready?
Re: Ed fields return NULL problem !
Quote:
Originally Posted by
Norm
Where is the value that you want assigned to the variable? If the value is being entered by a user, can the user tell the program when the value is ready?
It is in text field. Then you hit return /enter supposedly to store it.
Re: Ed fields return NULL problem !
Does the code have a listener to detect when the user presses Enter?
Re: Ed fields return NULL problem !
Re: Ed fields return NULL problem !
Then the code won't do what you want to the press of Enter.
Re: Ed fields return NULL problem !
Netbean adds them in.
Can you write me a sample actionlistener attached to a jtextfeild
Re: Ed fields return NULL problem !
Netbean adds them in.
Can you write me a sample actionlistener attached to a ????
Re: Ed fields return NULL problem !
Sorry, I don't use netbeans to write code and do not know what it does.
There must be some sample code like you are looking for on the internet. Have you tried to search for it?
Also look at the tutorial: http://docs.oracle.com/javase/tutori...nlistener.html