?
Solved

java.lang.ArrayStoreException

Posted on 2009-06-30
6
Medium Priority
?
904 Views
Last Modified: 2013-11-23
territoryArray = new APCTerritory[territoryList.size()];
                  territoryList.toArray(territoryArray);

this is giving

java.lang.ArrayStoreException: Object and inner type of array differs

whats the solution ?
0
Comment
Question by:cofactor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 400 total points
ID: 24744453
You need to use the correct type for what you hold in the List. The List does not hold type APCTerritory
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24744465
What does

System.out.println(territoryList.get(0).getClass());

print?
0
 
LVL 92

Expert Comment

by:objects
ID: 24744498
try this:

                  territoryArray  = (APCTerritory []) territoryList.toArray(new APCTerritory[0]);

though I suspect you have a different type of object strored in your list
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cofactor
ID: 24744588
>>The List does not hold type APCTerritory

true.

The list holds  Strings . i understand the exception now :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24744619
Yes, so you'd need something like
String[] territories = (String[])territoryList.toArray(new String[territoryList.size()]);

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24752606
:-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question