Results 1 to 2 of 2
- 08-01-2007, 04:05 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Cast Error Caught (change) Class is really: java.lang.String
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:
_secondVector is simply of the Vector class. this, i thought returned an Object. However, the exception handler prints out:Java 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(); }
can anyone shed some light on why obj is a String instead of an Object?Java Code:Cast Error Caught (change) Class is really: java.lang.String
i tried changing the line:
to:Java Code:Integer y = (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:Java Code:Integer y = new Integer(obj);
So now it's telling me that obj is an object, and before that it was a string......Java Code:cannot resolve symbol symbol : constructor Integer (java.lang.Object) location: class java.lang.Integer Integer y = new Integer(obj);
Thanks.
- 08-02-2007, 04:07 PM #2
Member
- Join Date
- Aug 2007
- Posts
- 47
- Rep Power
- 0
Similar Threads
-
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
By baltimore in forum New To JavaReplies: 2Last Post: 09-18-2008, 07:30 AM -
How to cast an Object into a specific type (Integer/String) at runtime
By mailtogagan@gmail.com in forum Advanced JavaReplies: 2Last Post: 12-03-2007, 01:04 PM -
Error: cannot be applied to (java.lang.String)
By carl in forum New To JavaReplies: 1Last Post: 08-05-2007, 06:33 AM -
Error: java.lang.InterruptedException is not caught and does not appear...
By fernando in forum Advanced JavaReplies: 1Last Post: 07-31-2007, 05:52 AM -
Can't convert java.lang.String to int.
By Albert in forum AWT / SwingReplies: 2Last Post: 07-13-2007, 05:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks