Home > Archive > Java Help > March 2004 > Casting to Integer on Stack, classcastexception
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Casting to Integer on Stack, classcastexception
|
|
|
|
| Lothar Kimmeringer 2004-03-27, 12:30 am |
| On Thu, 25 Mar 2004 20:58:56 +0000, Jeffrey Spoon wrote:
> Hello, I'm getting a ClassCastException and I'm not sure why.
You push a String on the stack and cast it to Integer when
getting it back. This lead to the exception. You have to
create an Integer out of the String (e.g. with new Integer(token))
and push that instead.
Regards, Lothar
--
Lothar Kimmeringer E-Mail: spamfang@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!
| |
| Eric Sosman 2004-03-27, 12:30 am |
| Jeffrey Spoon wrote:
>
> Hello, I'm getting a ClassCastException and I'm not sure why. [...]
Because you push each operand onto the stack as a String
object. When an operator comes along, you pop them off and
try to cast them to Integer objects. Strings aren't Integers.
--
Eric.Sosman@sun.com
| |
| Jeffrey Spoon 2004-03-28, 10:36 pm |
| In message <ahuxuoaa4q8w.dlg@kimmeringer.de>, Lothar Kimmeringer
<news200403@kimmeringer.de> writes
>On Thu, 25 Mar 2004 20:58:56 +0000, Jeffrey Spoon wrote:
>
>
>You push a String on the stack and cast it to Integer when
>getting it back. This lead to the exception. You have to
>create an Integer out of the String (e.g. with new Integer(token))
>and push that instead.
>
>
>Regards, Lothar
Doh... Thanks.
--
Jeffrey Spoon
| |
| Jeffrey Spoon 2004-03-28, 10:36 pm |
| In message <406359B9.7626D734@sun.com>, Eric Sosman
<Eric.Sosman@sun.com> writes
>Jeffrey Spoon wrote:
>
> Because you push each operand onto the stack as a String
>object. When an operator comes along, you pop them off and
>try to cast them to Integer objects. Strings aren't Integers.
>
Yep, that'll be why then. Cheers.
--
Jeffrey Spoon
|
|
|
|
|