Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.ArrayStoreException  RSS feed

 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After changing code as it works now:
>
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Shamayla
 
Sheriff
Posts: 21288
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Shamayla and Rob.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!