Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have one problem in inheriting CCSprites in Java. Here is part of my code:

public class Block extends CCSprite
  static Block temp=null;
  static Block newBlock(tetrominoTypes blockType)
    temp = (Block) Block.sprite(filename); // class cast exception here
    return temp;

A class cast exception occurs at run time on the indicated line, how can I resolve it?

share|improve this question
You know there's a new keyword in Java.. But I guess your error simply occurs because Block.sprite doesn't return a Block object, but a Sprite. – bummzack Oct 4 '11 at 6:44
Never, never post a question about an error, without providing the error detail. It is totally unconstructive. Fastest way to get downvoted. Also, this question really belongs on stackoverflow, not gamedev. – Arcane Engineer Oct 4 '11 at 8:19
Suspiciously like – user744 Oct 4 '11 at 8:28

The documentation for Java's cast exception indicates that it is thrown when there is an attempt "to cast an object to a subclass of which it is not an instance."

In your case, whatever Block.sprite() returns is not something you can cast to a Block object. Since "sprite" appears to be a static member function of the Block class which you have not posted, there's not a whole lot more we are going to be able to do for you.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.