We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

java.lang.ArrayStoreException

cofactor
cofactor asked
on
Medium Priority
992 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 ?
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2016

Commented:
What does

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

print?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
try this:

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

though I suspect you have a different type of object strored in your list

Author

Commented:
>>The List does not hold type APCTerritory

true.

The list holds  Strings . i understand the exception now :)
CERTIFIED EXPERT
Top Expert 2016

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

Open in new window

CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.