Hi, I was getting a class cast exception in part of my code (using Java 2 sdk 1.4.1). I added an exception handler and the following is the section of the code:
Object obj = _secondVector.get(i);
try{
Integer y = (Integer)obj;
_firstVector.set(y.intValue(), "<<<remove>>>");
}catch(ClassCastException e){
System.err.println("Cast Error Caught (change)");
System.err.println("Class is really: " + obj.getClass().getName());
e.printStackTrace();
}
_secondVector is simply of the Vector class. this, i thought returned an Object. However, the exception handler prints out:
Cast Error Caught (change)
Class is really: java.lang.String
can anyone shed some light on why obj is a String instead of an Object?
i tried changing the line:
Integer y = (Integer)obj;
to:
Integer y = new Integer(obj);
Because it said that obj was actually a String and there is an Integer constructor with String as the argument, but i get:
cannot resolve symbol
symbol : constructor Integer (java.lang.Object)
location: class java.lang.Integer
Integer y = new Integer(obj);
So now it's telling me that obj is an object, and before that it was a string......
Thanks.