It's not a secret anymore!
The moose likes Beginning Java and the fly likes Error When trying to display Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error When trying to display" Watch "Error When trying to display" New topic

Error When trying to display

Jesse Walker
Ranch Hand

Joined: Aug 18, 2004
Posts: 50
I have tried to write a program that displays the selected item from a JList but what I get is the following LJava.lang.Object:@7ca8\

The following is my code(WHERE DID I GO WRONG???)

JFrame f = new JFrame("Order Please");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
String[] items = { "Ketchup", "Mustard", "Pickle", "Onion", "Tomato",
"Lettuce", "Mayonise"};
final JList list = new JList(items);
String [] items2 = {"Beef", "Chicken", "Beef", "Veggie"};
JComboBox maincourse = new JComboBox(items2);
JButton mybutton = new JButton("Print");
mybutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Object[] selection = list.getSelectedValues();
String[] selection2 = (String)selection;
Container content = new JPanel();
f.setLocation(300, 300);
Mattias Arthursson
Ranch Hand

Joined: Jul 26, 2004
Posts: 90
You are passing the entire array to println():

This will call toString() on your Object array, which will produce the output you're getting.

Try printlng out the contents of the array instead, e.g.:

Admit nothing. Blame everyone. Be bitter.
I agree. Here's the link:
subject: Error When trying to display
It's not a secret anymore!