TextField NULL


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: TextField NULL

  1. #1
    Join Date
    Mar 2005
    Posts
    8

    TextField NULL

    hi,
    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?
    Red Rabbit

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    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....
    eschew obfuscation

  3. #3
    Join Date
    Mar 2005
    Posts
    8

    Figured it out, kinda!!

    hi,
    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?
    RedRabbit

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    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.
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center