• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with JTextField null

 
Nicolas Sebastian Vidal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all, i've a problem when i try to return the object "JTextField" because this is empty (null) and i don't know wich is the structure to use. In my method i use a Queue but this structure can't contains null objects. Please HELP.


 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to me you would have a problem because you don't ever assign an object to the "queue" variable. However it would help if you told us the details -- in other words, if you described your problem. Does your program not compile? Does it run but throw an exception? Does it run but not do what you expected? And if there are error messages or stack traces, post them.
 
Nicolas Sebastian Vidal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Seems to me you would have a problem because you don't ever assign an object to the "queue" variable. However it would help if you told us the details -- in other words, if you described your problem. Does your program not compile? Does it run but throw an exception? Does it run but not do what you expected? And if there are error messages or stack traces, post them.


sorry, my problem is this when i run it:



 
Paul Adcock
Ranch Hand
Posts: 48
Firefox Browser Java Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
queue.offer((JTextField) component[i]);

You never changed queue from null before you made that call.

Oh, DB already covered that.

Queue is an interface.

You can't directly initialize a Queue object with the new keyword anyway. (You can initialize it to a Queue implementing class that isn't abstract.)

What's more, Queue is a generic class.

If you don't specify the type of Queue, I think it default to Queue<Object>.

Also, just out of curiosity, what are you going to do is queue.peek() returns a JPanel object instead of a JTextField?

Why would it have null objects anyway unless there weren't any components in the JPanel?

Anyway, you can add null items to a Queue I think. You can to a LinkedList (which is a Queue implementer) and to ArrayList.

import java.util.ArrayList;
import java.util.LinkedList;

public class TempFile
{

public static void main(String[] args)
{
ArrayList<String> list = new ArrayList<String>();
LinkedList<String> list2 = new LinkedList<String>();


list.add("Items");
list.add(null);
list.add("Bob");

System.out.println(list.toString());

list2.add("Items");
list2.add(null);
list2.add("Bob");

System.out.println(list2.toString());


}





}


[Items, null, Bob]
[Items, null, Bob]


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic