jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes java.lang.ArrayStoreException (S.O.S) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.lang.ArrayStoreException (S.O.S)" Watch "java.lang.ArrayStoreException (S.O.S)" New topic

java.lang.ArrayStoreException (S.O.S)

Jack Danyells

Joined: May 27, 2005
Posts: 3
If anyone has an idea as to how I can solve this please let me know:

I am running
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_07-b05)
Java HotSpot(TM) Client VM (build 1.4.2_07-b05, mixed mode)

In my method I have the following:

ProfileValue pv = new ProfileValue();

I call this method by doing the following:

Vector retVal = new Vector();
retVal = pm.setAllSubProfilesSelected(cid, topLevelIdsEqual);

Then when I try to convert the Vector into an Array it fails and throws an

This is the line that breaks: (all on one line)
String[] subLevelArray = (String[]) retVal.toArray(new String[retVal.size()]);
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Hi Jack,

You're putting ProfileValue objects into the Vector, and then trying to get the Vector to store them in a String[]; hence the exception. You have several choices: make the method put just the Strings into the Vector; use ProfileValue[] instead of String[] in the toArray() call -- or call toArray() with no arguments to get an Object[].

[Jess in Action][AskingGoodQuestions]
Jack Danyells

Joined: May 27, 2005
Posts: 3
I resolved this thanks for the information though, I was adding objects not strings to the Vector.
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Notice that Strings are objects, too.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link: http://aspose.com/file-tools
subject: java.lang.ArrayStoreException (S.O.S)
It's not a secret anymore!