Ed fields return NULL problem !
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Ed fields return NULL problem !

  1. #1
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    52

    Unhappy 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);

    }

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,756

    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.
    Last edited by Norm; March 6th, 2017 at 07:23 AM.
    Norm

  3. #3
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    52

    Question Re: Ed fields return NULL problem !

    Quote Originally Posted by Norm View Post
    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?

  4. #4
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,756

    Re: Ed fields return NULL problem !

    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?
    Norm

  5. #5
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    52

    Re: Ed fields return NULL problem !

    Quote Originally Posted by Norm View Post
    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.

  6. #6
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,756

    Re: Ed fields return NULL problem !

    Does the code have a listener to detect when the user presses Enter?
    Norm

  7. #7
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    52

    Re: Ed fields return NULL problem !

    None that I wrote

  8. #8
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,756

    Re: Ed fields return NULL problem !

    Then the code won't do what you want to the press of Enter.
    Norm

  9. #9
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    52

    Re: Ed fields return NULL problem !

    Netbean adds them in.
    Can you write me a sample actionlistener attached to a jtextfeild

  10. #10
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    52

    Re: Ed fields return NULL problem !

    Netbean adds them in.
    Can you write me a sample actionlistener attached to a ????

  11. #11
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,756

    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
    Norm

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)