【问题标题】:Could someone help me debug my app (not very big)?有人可以帮我调试我的应用程序(不是很大)吗?
【发布时间】:2011-06-08 20:50:51
【问题描述】:

不确定是否可以在此处请求此类帮助,如果不可以,请告诉我。

它必须在明天之前完成,它还没有完全完成,但现在应该可以工作了。我正在尝试使用 Eclipse 调试器(不太习惯)。

好的,我在另一个项目文件夹中有一个名为“调试”的旧类,它是一个调试测试。我没有给它起这个名字,这是一个任务。它似乎引起了一些问题,将其删除,现在我的堆栈跟踪要小得多。

我尝试调试 Board 构造函数,将构造函数中的原始代码添加到方法中,并尝试在构造函数中运行该方法。这没有任何区别,但仍然如此。

现在堆栈跟踪如下所示:

Thread [main] (Suspended)   
Board(Object).<init>() line: 20 
Board.<init>() line: 9  
Game.<init>() line: 15  
Game.main(String[]) line: 11    

板子构造器:

公共课板{

private int COLUMNS = 8;
private int ROWS = 8;
private Square[][] grid;

public Board(){
    addGrid();
}

public void addGrid(){
    grid = new Square[COLUMNS][ROWS];
    for(int row = 0; row < 8; row++){
        for(int col = 0; col < 8; col++){
            grid[col][row] = new Square(this);
        }
    }
}

方形构造函数:

public class Square {

    private Piece piece;
    private Board board;

    public Square(Board b){
        board = b;
    }

在我的断点中,我注意到了这一点:

ArrayIndexOutOfBoundsException: caught and uncaught 

又试了一次,结果和以前差不多:

Thread [main] (Suspended)   
ClassNotFoundException(Throwable).<init>(String, Throwable) line: 217   
ClassNotFoundException(Exception).<init>(String, Throwable) line: not available 
ClassNotFoundException.<init>(String) line: not available   
URLClassLoader$1.run() line: not available  
AccessController.doPrivileged(PrivilegedExceptionAction<T>, AccessControlContext) line: not available [native method]   
Launcher$ExtClassLoader(URLClassLoader).findClass(String) line: not available   
Launcher$ExtClassLoader.findClass(String) line: not available   
Launcher$ExtClassLoader(ClassLoader).loadClass(String, boolean) line: not available 
Launcher$AppClassLoader(ClassLoader).loadClass(String, boolean) line: not available 
Launcher$AppClassLoader.loadClass(String, boolean) line: not available  
Launcher$AppClassLoader(ClassLoader).loadClass(String) line: not available  
Board.addGrid() line: 14    
Board.<init>() line: 10 
Game.<init>() line: 15  
Game.main(String[]) line: 11    

【问题讨论】:

  • 当然,我添加了 Board 类的第一部分。我尝试从断点开始,就在 Board 构造函数的第一行。它给了我几乎相同的例外。

标签: java eclipse debugging exception


【解决方案1】:

无论出于何种原因,您的 Game 类都看不到 Board 类。如果您发布的代码部分是正确的,那似乎是因为它们在代码顶部没有包声明。您需要在代码的第一行添加一些类似的内容:

package boardGame;

public class Board {

等等。在每节课开始时。此外,包名必须与包含源文件的文件夹的名称相同。

【讨论】:

  • 嘿,对不起。有些课程使它看起来像一个更大的交易,编辑我的帖子。我还需要将东西放入新包装中吗?
  • 好吧,如果您在顶部有正确的包声明,它将起作用,这就是我所说的。另一个问题:您发布的堆栈跟踪中的第 20 行是哪一行?当你运行程序时它给你什么异常或错误?
猜你喜欢
  • 2022-07-07
  • 1970-01-01
  • 2013-04-08
  • 2020-03-25
  • 1970-01-01
  • 2017-12-09
  • 2022-06-11
  • 2019-09-10
  • 2016-07-25
相关资源
最近更新 更多