代码之家  ›  专栏  ›  技术社区  ›  DanM

调试时如何处理ClassNotLoadedException?

  •  25
  • DanM  · 技术社区  · 16 年前

    因此,我正在Eclipse中(远程)调试java/jboss应用程序,逐行进行调试。在某一点上,一组 GridSquare 物体( 是一个相当简单的独立类,包含一些属性和方法),通过方法调用创建,即:

    GridSquare[] squares = this.theGrid.getSquares(14, 18, 220, 222);

    squares 数组中确实填充了 对象,我在单步执行代码和调试时会遇到一些奇怪的情况。如果我尝试查看 数组,而不是我得到的值:

    org.eclipse.debug.core.DebugException: com.sun.jdi.ClassNotLoadedException: Type has not been loaded occurred while retrieving component type of array.

    …有人知道这是怎么回事吗?

    6 回复  |  直到 13 年前
        1
  •  27
  •   Yishai    16 年前

    基本上,这意味着类加载器没有加载GridSquare[]类。尽管如此,在某种程度上它听起来像是调试器中的一个bug。与代码的断点关联似乎有点中断。要么需要重新编译以同步行号,要么正在发生其他问题。在代码中的那个点(赋值之后),需要加载它。除非getSquares实际返回一个子类(GridSquaresublass[]),此时JVM可能还没有加载它,因为它还不需要它。

        2
  •  1
  •   James Watkins    9 年前

    我遇到这个错误是因为我在使用反射的代码上运行单元测试。我制作了一个特殊的类来测试代码的所有特性。Junit显然为测试类使用了一个单独的类加载器(这很有意义),所以我的代码无法对该类使用反射。我得到的堆栈跟踪非常通用(java.lang.InstanceionException),但当我在调试模式下检查时,异常对象本身有更多细节(org.eclipse.debug.core.DebugException:com.sun.jdi.ClassNotLoadedException),这让我得出了这个结论。

    因此,我将这个特殊类移动到了主类加载器(通过将文件从src/test/java移动到src/main/java),它工作得很好。我不喜欢这个解决方案,但我想不出替代方案。就我而言,这没什么大不了的,但我可以看出这可能会引起其他人的担忧。

        3
  •  0
  •   studgeek    13 年前

    我在Eclipse中看到过这种情况,当子类的类变量隐藏父类的变量时。不知何故,这混淆了Eclipse(而且通常是个坏主意:)。例如:

    class A {
       private String a;
    }
    
    class B extends A {
       public String a;
    }
    
        4
  •  0
  •   juldeh    10 年前
    //Give a SIZE to the array:
    GridSquare[] squares = GridSquare[this.theGrid.size()];
    
    //Fill each element of the array with the object constructor to avoid the null value
    for(int i=0; i<this.theGrid.size(); i++){
        squares[i] = new GridSquare();
        squares[i] = this.theGrid.getSquares(14, 18, 220, 222);
    }
    
        5
  •  -1
  •   Sanditha Shetty    11 年前

    通过初始化GridSquare可以解决这个问题。 正方形=新的网格正方形();

        6
  •  -3
  •   Raghavendra Nanjundappa    11 年前