Hi, I have the following : // setObj is a TreeSet and elems and elems2 are ArrayLists (both seem to be set up fine - a.k.a used elsewhere but elems and elems2 are Arrays for (int i = 0; i <= currItem; i++) { setObj.add(new Object[] { (String)elems.get(i), new Double(Double.parseDouble(elems2.get(i))) }); }
// With the above I get the following error The method parseDouble(String) in the type Double is not applicable for the arguments (Object) // When I try to cast the value inside the parseDOuble method I get the following java.lang.ClassCastException: [Ljava.lang.String;
How can I use the ArrayLists in this method? Some sort of casting I need to do or something along those lines? Thanks in advance for any help.
Here's the code that generates the elems and elems2. (Going by your response) I'm guessing the way I'm splitting up the string (i.e. strIn) is where the problem lies then. If this is the case how can I break a incoming string up and assign it to an ArrayList in one shot? Thanks for the response.
while ((strIn = dataFile.readLine()) != null) { //****** Tab-delimited Records ****************************************** readArray.add((Object)strIn.split("\t")); //****** If more than 1 line then line is a header line ****************** if (readArray.size() > 1) { if (passData != 0) { elems.add(currItem, (Object)readArray.get(Integer.parseInt(request.getParameter("PAxis")))); elems2.add(currItem, (Object)readArray.get(Integer.parseInt(request.getParameter("SAxis")))); if (request.getParameter("COMPAREPRIM") != null && request.getParameter("COMPARESEC") != null) { elems3.add(currItem, (Object)readArray.get(Integer.parseInt(request.getParameter("COMPAREPRIM")))); elems4.add(currItem, (Object)readArray.get(Integer.parseInt(request.getParameter("COMPARESEC")))); } currItem++; } passData = 1; } }
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
// When I try to cast the value inside the parseDOuble method I get the following java.lang.ClassCastException: [Ljava.lang.String;
What kind of objects do the ArrayLists contain? The "[L" part of the error message means that there is an array of String -not just a singular String-, which can't be cast to a double.
String.split returns a String[], not String. (The cast to Object is not necessary, by the way.)
Are you trying to add all parts of strIn to "elems" individually? Then you might use "elems.addAll(Arrays.asList(strIn.split(...)))", if that doesn't screw up the ordering.
Rob Hunter
Ranch Hand
Joined: Apr 09, 2002
Posts: 788
posted
0
Hi Ulf, Thanks for the response. I just resorted back to using the String[] since I still could in this case. I just wanted to try subbing in ArrayList and try that out. I'll give that a try once I get a chance. Thanks again.
Rob
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
Originally posted by Ulf Dittmer: you might use "elems.addAll(Arrays.asList(strIn.split(...)))", if that doesn't screw up the ordering.
It shouldn't screw up the ordering, should it?
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