• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.ArrayStoreException  RSS feed

 
Andy Powell
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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
 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats odd..

If I run the following :




I get

 
Paul Clapham
Sheriff
Posts: 22817
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
joni novhia
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shailesh pratapwar welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!