出错位置报错为:Error report is :
org.eclipse.debug.core.DebugException: com.sun.jdi.ClassNotLoadedException:
Type has not been loaded occurred while retrieving component type of array.代码的目的是 创建一个国际象棋棋盘 然后把每一个格子都存到一个二维队列cas中去文件1
package abc;
// abc stands for a board for chess/*
* File: Checkerboard.java
* -----------------------
* This program draws a checkerboard. The dimensions of the
* checkerboard is specified by the constants NROWS and
* NCOLUMNS, and the size of the squares is chosen so
* that the checkerboard fills the available vertical space.
*/import acm.graphics.*;
import acm.program.*;public class Checkerboard extends GraphicsProgram {/**
*
*/
private static final long serialVersionUID = 1L;
public void run() {
double sqSize = (double) getHeight() / NROWS;
Cas[][] cas = new Cas[NROWS + 2][NCOLUMNS+2];
for (int i = 0; i < NROWS; i++) {
for (int j = 0; j < NCOLUMNS; j++) {
double x = j * sqSize;
double y = i * sqSize;
GRect sq = new GRect(x, y, sqSize, sqSize);
sq.setFilled((i + j) % 2 != 0);
(cas[i + 1][j + 1]).setToRect(sq); //这里出错了 add(sq);
}
}
}/* Private constants */
private static final int NROWS = 8; /* Number of rows */
private static final int NCOLUMNS = 8; /* Number of columns *//* Standard Java entry point */
/* This method can be eliminated in most Java environments */
public static void main(String[] args) {
new Checkerboard().start(args);
}
}
文件2
package abc;
import acm.graphics.GRect;
public class Cas {
//attribute
private GRect ToRect= null;
private boolean occupied;
public Cas(){
occupied = false;
}
public boolean occupied(){
return occupied;
}
public GRect getToRect(){
return ToRect;
}
public void setToRect(GRect pointer){// be care of the "pointed and pointer"
ToRect = pointer;
}
}
//important
//click on a rect, how to reach the logic chess,
出错位置报错为:Error report is :
org.eclipse.debug.core.DebugException: com.sun.jdi.ClassNotLoadedException:
Type has not been loaded occurred while retrieving component type of array.
org.eclipse.debug.core.DebugException: com.sun.jdi.ClassNotLoadedException:
Type has not been loaded occurred while retrieving component type of array.代码的目的是 创建一个国际象棋棋盘 然后把每一个格子都存到一个二维队列cas中去文件1
package abc;
// abc stands for a board for chess/*
* File: Checkerboard.java
* -----------------------
* This program draws a checkerboard. The dimensions of the
* checkerboard is specified by the constants NROWS and
* NCOLUMNS, and the size of the squares is chosen so
* that the checkerboard fills the available vertical space.
*/import acm.graphics.*;
import acm.program.*;public class Checkerboard extends GraphicsProgram {/**
*
*/
private static final long serialVersionUID = 1L;
public void run() {
double sqSize = (double) getHeight() / NROWS;
Cas[][] cas = new Cas[NROWS + 2][NCOLUMNS+2];
for (int i = 0; i < NROWS; i++) {
for (int j = 0; j < NCOLUMNS; j++) {
double x = j * sqSize;
double y = i * sqSize;
GRect sq = new GRect(x, y, sqSize, sqSize);
sq.setFilled((i + j) % 2 != 0);
(cas[i + 1][j + 1]).setToRect(sq); //这里出错了 add(sq);
}
}
}/* Private constants */
private static final int NROWS = 8; /* Number of rows */
private static final int NCOLUMNS = 8; /* Number of columns *//* Standard Java entry point */
/* This method can be eliminated in most Java environments */
public static void main(String[] args) {
new Checkerboard().start(args);
}
}
文件2
package abc;
import acm.graphics.GRect;
public class Cas {
//attribute
private GRect ToRect= null;
private boolean occupied;
public Cas(){
occupied = false;
}
public boolean occupied(){
return occupied;
}
public GRect getToRect(){
return ToRect;
}
public void setToRect(GRect pointer){// be care of the "pointed and pointer"
ToRect = pointer;
}
}
//important
//click on a rect, how to reach the logic chess,
出错位置报错为:Error report is :
org.eclipse.debug.core.DebugException: com.sun.jdi.ClassNotLoadedException:
Type has not been loaded occurred while retrieving component type of array.
cas[i + 1][j + 1] = new Cas(); //对象都没有new,又怎么能调用方法?
new不是调用这个构造函数么?
public Cas(){
occupied = false;
}
这里面应该没有 Cas对象吧 你没忘里面防止对象吧?
这个只是new一个数组对象,数组的元素没有new,也就是说数组的元素都是null,不会调用构造函数的
只有cas[i + 1][j + 1] = new Cas(); 针对具体的数组元素new一个对象,才会调用构造函数