File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes problem with JTextField null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem with JTextField null" Watch "problem with JTextField null" New topic
Author

problem with JTextField null

Nicolas Sebastian Vidal
Greenhorn

Joined: Jul 05, 2012
Posts: 2
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jul 05, 2012
Posts: 2
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

Joined: Jan 22, 2011
Posts: 48

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]



Repeal Obamacare.
http://www.dontfundobamacare.com/
http://liberty-amendments.freeforums.net/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with JTextField null