Solved

java.lang.ArrayStoreException

Posted on 2009-06-30
6
898 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

730 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