Results 1 to 6 of 6
  1. #1
    no-one is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default Casting classX to classX problem

    i am currently writing some extensions To my SmartFoxServer (its used for multi player games etc.)

    The software has some classes that both the software and any extensions use (Room and User). the developers have made a map called "properties" where you can store object / variables related to that object. (the map is currently a HashMap)

    Now to the problem.

    i have created a class that i call Cw2Game and i create a new instance of that object and and add it to the properties map for each game room i create.
    i am doing something like this :

    Cw2Game game = new Cw2Game ();
    gameRoom.properties.put("gameObject", game);

    Now later when i need that object i try to do something like this:

    Cw2Game game = (Cw2Game) gameRoom.properties.get("gameObject");

    And this code compiles perfectly fine however on runtime i get the following error:
    Java Code:
    Exception in ExtensionHandler:
    java.lang.ClassCastException:
    net.m0rkeulv.games.cw2.Cw2Game
    Cannot be cast to
    net.m0rkeulv.games.cw2.Cw2Game

    to me this donít make any sense as the error shows that both object and type is the same ?

    has anyone had this problem before ? or got any idea on how i may solve it ?

    btw i have already tried different approaches with Cw2Game.Class.cast() and obj.getClass()

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You have every reason to be upset with such a message.
    Do you have multiple versions of this class on the classpath?

  3. #3
    no-one is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default

    As far as i know i only got one version of the file. and i donít really see how i could have multiple version in the same classpath. then again i am not that familiar with java.

    The class name is never used elsewhere in my project so that class is the only one with that name, Smartfox only loads classes from one location and i have completely wiped it and the only files there are from this project so i donít really understand why i get this error

  4. #4
    no-one is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default

    after mailing smartfox i finally got an answer to my problem.
    each extension i make will use a separate Class Loader.
    and as i was trying to cast the object from a different extension i was also trying to cast it with a different Class loader.

  5. #5
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

    Default

    Similar problem exists with Eclipse Plugin development.
    Where you use classloader from other plugin to cast to other class.
    "There is no foolproof thing; fools are too smart."
    "Why can't you solve my Problem ?"

  6. #6
    johnwcv is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by no-one View Post
    after mailing smartfox i finally got an answer to my problem.
    each extension i make will use a separate Class Loader.
    and as i was trying to cast the object from a different extension i was also trying to cast it with a different Class loader.
    How did you solve it?

Similar Threads

  1. Casting
    By zzpprk in forum Advanced Java
    Replies: 13
    Last Post: 08-13-2009, 07:59 PM
  2. What does casting mean?
    By sev51 in forum New To Java
    Replies: 3
    Last Post: 01-27-2009, 04:31 PM
  3. casting help
    By soc86 in forum New To Java
    Replies: 4
    Last Post: 01-13-2009, 11:07 PM
  4. Casting problem
    By John_28 in forum New To Java
    Replies: 6
    Last Post: 05-14-2008, 11:29 AM
  5. Casting
    By leebee in forum New To Java
    Replies: 5
    Last Post: 08-10-2007, 12:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •