wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes why? this piece of code is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "why? this piece of code is not working" Watch "why? this piece of code is not working" New topic
Author

why? this piece of code is not working

joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
String sexbox[] = {"Male","Female"};
String marbox[] = {"Married","Single","Deviorced"};
JComboBox sexcb = new JComboBox();
sexcb.addItem(sexbox);

JComboBox mar_statuscb = new JComboBox();
mar_statuscb.addItem(marbox);

the error i get is:<identifier> expected
what can i do ?

[ January 16, 2008: Message edited by: joseph okon ]
[ January 16, 2008: Message edited by: joseph okon ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38040
    
  22
It is because you called it "sexcd" in one place and "sexcb" in another.
Mark Newton
Ranch Hand

Joined: Jan 31, 2006
Posts: 129
Did Campbell's solution solve your problem? You seem to have edited your code to fix the mistake that Campbell pointed out. Does that mean the problem's fixed?
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by joseph okon:
String sexbox[] = {"Male","Female"};
JComboBox sexcb = new JComboBox();
sexcb.addItem(sexbox);


You are adding the array itself as an item to the combo box.
This will result in only a single item in the box, which the
renderer will show as something ugly like [Ljava.lang.String;@123456

You probably want to add each item of the array to the combo box.
The easy way is do just do JComboBox sexcb = new JComboBox(sexbox).
You could also do
sexcb.addItem(sexbox[0]);
sexcb.addItem(sexbox[1]);


bitguru blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why? this piece of code is not working
 
Similar Threads
Internal Error while Validating username and password
why the below highlighted line is not showing unreachable compile error.
trapping two appearance of a character
error - HTTP Status 404 - /EmailList/
Cleared SCJP 1.5 with 91%