Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.ArrayStoreException

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

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Shamayla
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
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: 632
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