• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

JSpinner does not work for Numbers

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can you please have a look at the following code to figure out why my customer JSpinner throws a runtime "java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Integer" error ?

>
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Javadoc for the SpinnerNumberModel constructor you're calling says


All of the parameters must be mutually Comparable, value and stepSize must be instances of Integer Long, Float, or Double.

 
Sheriff
Posts: 22850
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need to create your own version of SpinnerNumberModel. Fortunately the source is available in the src.zip file inside your JDK folder.
 
ulvi ugur
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Guys,

I tried Ernest's path and used the constructor with Comparables but this time it started throwing casting exceptions about Byte and BigInteger which told me that I have to go either in the src from JDK or do my own stuff.

Thanks Rob, that was a good advice, generating another class for this feels a bit of an overkill but totally made sense compared to this "casting chaos".

Thanks and cheers,

Ulvi

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic