• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dynamic SelectBox

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all coders ! I'm in trouble 'cause I alwais receive this error when I'm working with this component ( it's a generator of a html select box based on a query on a single column that allows the user to select many values from it but giving also the chance to remove it if not necessary ).
Here's the error :
java.lang.ClassCastException: java.lang.String cannot be cast to [[Ljava.lang.Object;
at it.consumer.DynamicSelect.doGet(DynamicSelect.java:92)

Here's the code

Don't look at all System.out.println... just visual debug ;)
Hopin' the community can help me, I wish good work at all
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error explains itself. You are trying to cast a string object to a an array. No can do.

In your later code you set the value of the scoped variable to one of an array or a string. Apparently the latter has occurred. That's all pretty messy. And it's a really poor idea to builf HTML in strings in a servlet. Why are you using this approach?
 
DecK DecKer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's just an exercise. the goal of this servlet is to create only the select box... that can be used for future project
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, be aware that in the real world, generating markup in a servlet would be frowned upon.

The fact remains that you are trying to cast incorrectly. Why do you set the value of the scoped variable to a string sometimes, and an object at others? Later on, how are you supposed to know which one to cast it to?
 
reply
    Bookmark Topic Watch Topic
  • New Topic