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
Solved

java.lang.ArrayStoreException

Posted on 2009-06-30
6
897 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL  on Tomcat 8 68
ejb entity bean example issue 2 16
Java 8 to Java 6 8 20
What browser will run Java? 7 46
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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 …

808 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