Solved

java.lang.ArrayStoreException

Posted on 2009-06-30
6
903 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 100 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
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!

 

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

Technology Partners: 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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

707 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