Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
1  
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. –  Nick Wiggill Oct 4 '11 at 8:19
    
Suspiciously like gamedev.stackexchange.com/questions/17939/subclass-ccsprite. –  user744 Oct 4 '11 at 8:28

1 Answer 1

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

 
discard

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.