• Post Reply Bookmark Topic Watch Topic
  • New Topic

casting problem at runtime  RSS feed

 
terry oliver
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please see following code and error message

public static Vector secondaryTurns(Vector<Double>secAmps, Vector<Double>secVolts, Vector<Double>secGa, double reg,double priTurns,double priVolts, double va)
{
Vector secTurns=new Vector();


for (int x=0; x<secGa.size(); x++)
{
secTurns.add((secVolts.get(x)*priTurns/priVolts)*(secVolts.get(x))*(secAmps.get(x))*reg/va);

System.out.println("sec Trn"+secTurns.get(x)+"position"+x);
}
return secTurns;
}

Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double
at EngineeringCalculations.secondaryTurns(EngineeringCalculations.java:696)
at transTest.main(transTest.java:73)
I have used similar methods using gauge as the counter without this error
help

tvolly
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Terry Oliver,
Welcome to JavaRanch.

A ClassCastException is a runtime exception that shows that an object is being cast to a subclass of which it is not an instance.

As, in the code you have used Generics. So, all the vectors can take an argument of type Vector.add(int,double) or Vector.add(double). So, here it is no chance that you can pass something other than double. Also, for normal doubles the int can be passed.

So, the only line that can cause problem is


Well, the things being in place that should be a feeble option. A

Are you sure that it is this section of code that is posing problems?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!