The Artima Developer Community
Sponsored Link

Java Answers Forum
ClassCastException

2 replies on 1 page. Most recent reply: Aug 27, 2003 4:55 AM by Senthoorkumaran Punniamoorthy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Chris Brooks

Posts: 6
Nickname: bioheel
Registered: Jul, 2003

ClassCastException Posted: Aug 27, 2003 3:44 AM
Reply to this message Reply
Advertisement
I cannot, for the life of me, figure out how to deal with this exception. I have included the code below but my basic problem is that when I call next in the Iterator and try to cast it as int I get this error. I have tried several ways to do it but all result in the same exception - help!

The Code:
public class CSVFile {

static Matrix m;
static int leng;
static int locationCount;
static double maxDistance;

public static void main(String[] args) throws IOException {

leng = args[0].length();

// Construct a new CSV parser.
CSV csv = new CSV();
BufferedReader is = new BufferedReader(new FileReader(args[0]));
process(csv, is);
PatchBuilder landscape = new PatchBuilder();
double intervalSize = Double.parseDouble(args[1]);
double numberOfClasses = (maxDistance/intervalSize);
for (int a=0;a<numberOfClasses;a++) {
double thresholdDistance = a*intervalSize;
landscape.BuildGraph(thresholdDistance);
System.out.println(thresholdDistance+","+landscape.averageClusterSize);
}
}

protected static void process(CSV csv, BufferedReader is) throws IOException {
String line;

int x = 0;
int y = 0;

m = new Matrix(new double[leng][leng]);
while ((line = is.readLine()) != null) {
System.out.println("line = `" + line + "'");
Iterator e = csv.parse(line);
while (e.hasNext())
x = ((Integer)e.next()).intValue();
y = ((Integer)e.next()).intValue();
double dist = Double.parseDouble(e.next().toString());
m.set(x,y,dist);

}
locationCount = m.getRowDimension();
for (int a=0;a<locationCount;a++) {
for (int b=0;b<locationCount;b++) {
double maxDistance = 0;
if (m.get(a,b)>maxDistance) {
maxDistance = m.get(a,b);
}
}
}
}
}


David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: ClassCastException Posted: Aug 27, 2003 4:32 AM
Reply to this message Reply
I'd need the code for the 'CSV' class.

Please post the Exception trace. It'll tell you what the object really was, rather than an Integer.

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: ClassCastException Posted: Aug 27, 2003 4:55 AM
Reply to this message Reply
x = ((Integer)e.next()).intValue();
y = ((Integer)e.next()).intValue();

I guess you are getting a ClassCastException at this point of your code if I have understood correct.

Why don't you do this! For testing purpose without casting modify the code a little.
System.out.println(e.next().getClass().toString());

This will help you to identify what is the Objects class which is returned by e.next(). Then you can proceed from there I guess.

Flat View: This topic has 2 replies on 1 page
Topic: How and where the statement compiled Previous Topic   Next Topic Topic: hi accesing database tthrough applet

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use