This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Spark in Action and have Jean-Georges Perrin on-line!
See this thread for details.
Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

problem with JTextField null

 
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.


 
Marshal
Posts: 25668
69
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:



 
Ranch Hand
Posts: 48
Firefox Browser Notepad Java
  • 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]


 
Seriously? That's what you're going with? I prefer this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic