This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

java.lang.ArrayStoreException

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again!

I'm trying to convert an arrayList of strings into a String array.
I'm using this


I don't know if this will help but this is what I get...


frame is the class that im trying to convert it in and i'm trying to put it into a combo in GUIness.
GUInessGo runs the whole GUI.

It compiles fine but when I run it it throws up a java.lang.ArrayStoreException.

Anyone know why?

I'd really appreciate some help.

Thanks everyone
 
Ranch Hand
Posts: 231
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats odd..

If I run the following :




I get

 
Marshal
Posts: 27291
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to ask us why. Just follow the ArrayStoreException link which goes to the API documentation. Which tells you exactly why and shows an example of how to make it happen.
 
Sheriff
Posts: 22667
127
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are all elements of the array list either Strings or null? Because that's all a String[] can contain - nothing else.
 
Andy Powell
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It didn't like the arrayList because I didn't specify that it contained strings.
Finally managed to sort it though thanks to all your help and guidance.

Thanks very much
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Elsey wrote:Thats odd..

If I run the following :



I get

run:
myStrings is 2 long
BUILD SUCCESSFUL (total time: 0 seconds)




The toArray(Object ar[]) method of collection class often throws this exception when the invoking array has any element which is not of type in the bracketed array.
so, this method is just to ensure the type of element to be same as of target array. If it thrown any exception, then we can just say its because of any software error when the wrong type data went in the invoking array.
 
Marshal
Posts: 76120
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
shailesh pratapwar welcome to the Ranch
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic