Getting class cast exception where both classes are exactly the same

后端 未结 5 1490
天涯浪人
天涯浪人 2020-11-27 07:16

I am doing a JBoss SEAM project and when I view a form I get this error.

java.lang.ClassCastException:
it.cogitoweb.csi.entity.csiorelav.CsiTipoLav cannot be         


        
5条回答
  •  没有蜡笔的小新
    2020-11-27 07:41

    As Joachim explained earlier, java.lang.ClassCastException typically occurs when two classloaders load the classes with the same name. However, i have come across another situation when this could occur.

    This could occur with some IDE's that automatically reloads classes that have been modified. In such cases there might be older versions of the class retained in memory causing ClassCastException.

    Here are a few ways you could resolve this issue :

    1. If you are writing a custom class loader, while loading a class make sure that the base/default class loader does not already have an instance of that class loaded.

    2. Make the class being loaded a sub-class of the class that is already loaded by the default class loader.

    3. Make the class being loaded implement an interface that is already loaded by the default class loader.

    More info here - http://www.jspwiki.org/wiki/A2AClassCastException

提交回复
热议问题