LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-21-2009, 03:01 AM   #1
vibinlakshman
Member
 
Registered: Dec 2008
Location: Kerala, India
Distribution: Ubuntu 11.10
Posts: 334

Rep: Reputation: 33
Cool How to add numbers in JComboBox


I will show a small snippet what i did :

1. JComboBox petList = new JComboBox();
2. petList.addItem(1);// also tried petList.addItem(new Integer(1));

When i tried to enter string in combo box its ok , working fine , but when tried to enter numbers its bit problem ..

Error shown ...

Error:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

Last edited by vibinlakshman; 02-21-2009 at 03:02 AM.
 
Old 02-21-2009, 02:10 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

You can always use "String.valueOf()":
Quote:
String s = String.valueOf(i);
petList.addItem(s);
Even easier, you can probably just concatenate an empty string:
Quote:
petList.addItem("" + i);
'Hope that helps .. PSM
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using bc to add numbers and put into variable disruptive Programming 3 05-26-2008 09:05 PM
Bash + How to add Hexadecimal numbers trscookie Programming 7 09-03-2007 04:22 PM
Perl add numbers in 2nd field twantrd Programming 6 10-19-2006 08:26 PM
Add consecutive numbers to a Chinese file tcma Linux - General 0 10-19-2004 03:25 PM
Help.. how do I add two numbers? Tengil Linux - Newbie 3 03-04-2004 12:58 PM


All times are GMT -5. The time now is 09:16 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration