Results 1 to 8 of 8
Thread: Won't set to textfield
- 11-03-2010, 06:04 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
Won't set to textfield
I'm creating an email interface using an arraylist and filehandling. The idea is that the user can select a line in the display table and that message will be displayed when they click view. I've gotten as far as setting the text in textfields on the view screen but it won't let me set the information from the array. The weird thing is that it will print out into the command prompt. Otherwise I get a nullpointerexception. Can anyone help?! Thanks in advance.
public void setToScreen(){
System.out.println(mail.get(0).getTo());
textField.setText(mail.get(row).getTo());
- 11-03-2010, 06:33 PM #2
Well, you're printing out two completely different things there: whatever is in the 0th index, and whatever is in the row index. What is row? Use a debugger, or at least some print statements, to figure out what's going on there.
- 11-03-2010, 08:19 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
Sorry, row is a variable that contains an int. I'm using Netbeans and I think there's a probkem with the generated code. Thanks for your help.
- 11-04-2010, 11:29 AM #4
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
Still doesn't work
I've tried more things and I still can't get it to work. Am I just missing something? Sorry if my code is a bit unclear.
public void displayOnScreen(){
//to test if the data is being passed properly
System.out.println(mail.get(row).getTo());
System.out.println(mail.get(row).getFrom());
System.out.println(mail.get(row).getSubject());
System.out.println(mail.get(row).getDate());
System.out.println(mail.get(row).getMessage());
//To assign the value from mail (arraylist) to a string (just in case). Row is an int value.
to = mail.get(row).getTo().toString();
from = mail.get(row).getFrom().toString();
subject = mail.get(row).getSubject().toString();
date = mail.get(row).getDate().toString();
message = mail.get(row).getMessage().toString();
//Setting the string to the textfield which doesn't work
toField.setText(to.toString());
fromField.setText(from.toString());
System.out.println("Setting");
subjectField.setText(subject.toString());
dateField.setText(date.toString());
body.setText(message.toString());
}
}
- 11-04-2010, 12:27 PM #5
I assumed row was an int. The question you need to figure out is, what value does row have when it's being passed in that causes the exception? Throw some print statements in there. Also print out the size of the ArrayList (or whatever mail is). Or better yet, use a debugger.
Honestly, most people here (myself included) would advise you to ditch the IDE-generated code and do it yourself. You'll save yourself (and other people trying to help you) a ton of headaches if you do so.
Code you post should be in the form of an SSCCE, and you should always use the code tags to preserve formatting.
- 11-04-2010, 01:35 PM #6
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
Have you tracked down what is the null that is throwing the error?
Add debug lines before you set the text to the textfield that displays the text you are trying to set and the textfield you are trying to set it to. I don't see constructor calls for the JTextField's and since you can set a null to them, its more likely that the JTextField hasn't been initialized properly or you aren't keeping the reference to it.
- 11-04-2010, 02:16 PM #7
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
I ditched the generated code as you suggested and created my own but the same thing is happening. Nothing is displaying in the textfields. It no longer throws a nullpointerexception though and using print statements I found out that the proper information is being passed through. I have also made sure that the textfields are properly declared and created. Thanks to you both for your help on this.
- 11-04-2010, 02:32 PM #8
Similar Threads
-
set focus to the textfield
By paty in forum New To JavaReplies: 2Last Post: 07-09-2010, 08:28 AM -
1 question regarding textfield
By henry in forum New To JavaReplies: 3Last Post: 06-16-2010, 03:56 AM -
TextField Example
By Java Tip in forum SWTReplies: 0Last Post: 07-25-2008, 02:21 PM -
[SOLVED] Textfield
By Fireking in forum New To JavaReplies: 2Last Post: 07-11-2008, 03:40 AM -
JSP - getting value from a textfield
By Java Tip in forum Java TipReplies: 0Last Post: 12-01-2007, 08:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks