GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes java.lang.ArrayStoreException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.lang.ArrayStoreException " Watch "java.lang.ArrayStoreException " New topic
Author

java.lang.ArrayStoreException

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Hi all I have ArrayList of type as <Double>. Now I want to convert this into String[]. But it throws java.lang.ArrayStoreException. As per docs
Thrown to indicate that an attempt has been made to store the wrong type of object into an array of objects.
But still not clear Here is my code



Life is easy because we write the source code.....
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

After changing code as it works now:
>
Shamayla Bukhari
Greenhorn

Joined: Jun 24, 2011
Posts: 4
Why are you first converting it to an object array. Just Iterate over the double list and store it in the string array by calling toString() on the List Items.

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Welcome to JavaRanch Shamayla
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Pramod P Deore wrote:Hi all I have ArrayList of type as <Double>. Now I want to convert this into String[]. But it throws java.lang.ArrayStoreException. As per docs
Thrown to indicate that an attempt has been made to store the wrong type of object into an array of objects.
But still not clear Here is my code


This code is trying to put Double objects into a String[]. That's not allowed.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Thanks Shamayla and Rob.
 
GeeCON Prague 2014
 
subject: java.lang.ArrayStoreException