Showing results for 
Search instead for 
Did you mean: 
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

java.lang.ClassCastException failed


java.lang.ClassCastException failed

Hey All,


When we check in the system gives error. we didn't understand why. but this only happens in flat parts. the designer says it has nothing to do with me. Usually it always happens :). Have you ever experienced such an error before? Have you experienced the solution?

Error code: java.lang.ClassCastException

Thank you



Casting is the process of type conversion, which is in Java very common because its a statically typed language. Type Casting only works when the casted object follows an is a relationship to the type you are trying to cast to. ClassCastException is a runtime exception raised in Java when you try to improperly cast a class from one type to another. It's thrown to indicate that the code has attempted to cast an object to a related class, but of which it is not an instance. It is good practice to guard any explicit casts with an instanceof check first:


if (myApple instanceof Fruit) {
Fruit myFruit = (Fruit)myApple;


In general, that's what a cast means: it tells the compiler that even though this assignment might fail, you're pretty certain that it won't. In exchange for allowing the code to compile, you assume the risk of a run-time exception.

Here are some basic rules to keep in mind when casting variables:


  • Casting an object from a sub class to a super class doesn't require an explicit cast.
  • Casting an object from a super class to a sub class requires an explicit cast.
  • The compiler will not allow casts to unrelated types.


Even when the code compiles without issue, an exception may be thrown at run time if the object being cast is not actually an instance of that class . This will result in the run time exception ClassCastException.


This seems very odd.  Assuming "flat parts" refers to sheetmetal parts with a flat pattern feature - but may be something totally different.


If you are able to check in CAD in general, then there must be more detail needed here for what is meant by "flat parts."

I suggest recreating the problem and posting the MS log. Without that there’s little chance of anyone knowing what happened under the hood.


We know there’s a class cast exception. What we need to figure out is WHY is there a class cast exception.

Top Tags