Java Hash Table casting

  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

I'm messing with JavaCC and I am trying to get the value of a variable that is in the hash table and it hates me.

Code: [ Select ]
//...
{double v; Token t;}
t = <IDENTIFIER> {v = (Double)varTable.get(t.image); }
//...
  1. //...
  2. {double v; Token t;}
  3. t = <IDENTIFIER> {v = (Double)varTable.get(t.image); }
  4. //...


"Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double"

I tried to cast it to "Integer" and "Float" just to see if it was specific to double, but it didn't work. I tried a few unheard of casting double methods but that didn't work either. Anybody know an alternative method to casting double? Or why it could not be working? I included java.util.*
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6243
  • Loc: Seattle, WA

Post 3+ Months Ago

So I'm assuming that the hash table is storing your values as strings? In that case you'll have to use String.parseDouble() to convert it back to a numeric value.
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

I figured it out RIGHT after I posted, but forgot about the post, lol sorry. I was totally ignoring that it was telling me what it returned was a string for some reason, meaning I stored my values as strings when I meant to store them as doubles. It just didn't register in my head LOL... senior moment.

Thanks, sorry.
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6243
  • Loc: Seattle, WA

Post 3+ Months Ago

No problem, lol

That's the one nice thing about debugging Java exceptions (as opposed to, say, C++): it usually tells you exactly what is wrong.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 80 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.