我得到了#34;无法编译的源代码 - 错误的树类型"错误和"不能 找到符号"错误我关闭编译保存,现在得到无法找到符号。似乎打破它的区域是我在AsteroidFields生成方法中初始化Asteroid()的地方,所以我觉得我的初始化是不正确的但我还没有弄清楚如何。
package asteroidfield;
import java.util.TreeSet;
import blobzx.BlobGUI;
import blobzx.SandBox;
import blobzx.SandBoxMode;
public class AsteroidField implements BlobGUI {
SandBox ast;
public static void main (String [] Args){
new AsteroidField();
}
public AsteroidField (){
ast = new SandBox();
ast.setSandBoxMode(SandBoxMode.FLOW);
ast.setFrameRate(15);
ast.init(this);
}
@Override
public void generate() {
// This is the line that is breaking the code.
Asteroid asteroid = new Asteroid();
}
}
package AsteroidField;
import blobzx.BlobUtils;
import blobzx.PolyBlob;
import java.awt.Point;
import java.util.Random;
public class Asteroid extends PolyBlob{
// private static Random random = new Random();
public Asteroid(int velX, int velY, double rot) {
super(-100, -100, rot);
setDelta(velX, velY);
Random sides = new Random();
Random dist = new Random();
int si = sides.nextInt(9 - 5 + 1) + 5;
int di = dist.nextInt(15 - 5 + 1) + 5;
double region = (2 * Math.PI) / si;
double []angle = new double [si];
int [] xInt = new int[si];
int [] yInt = new int[si];
double [] x = new double [si];
double [] y = new double [si];
System.out.print("m");
for(int i = 0; i < si; i++){
angle[i] = (i*region)+(Math.random()*region);
Point cord = BlobUtils.rotatePoint(di, angle[i]);
x[i] = cord.getX();
y[i] = cord.getY();
}
for (int i = 0; i > x.length; i ++){
xInt[i] = (int) x[i];
yInt[i] = (int) y[i];
}
setPolygon(xInt, yInt);
}
}
答案 0 :(得分:2)
我看到两个问题:
1)可能因为,你写道:
Asteroid asteroid = new Asteroid();
但是Asteroid类没有默认的construstor(至少,我没有在你的代码中看到它)
public Asteroid(int velX, int velY, double rot) {
2)或者可能是因为你使用的不是同一个包而不是在AsteroidField中使用import
package asteroidfield;
...
package AsteroidField;
你应该或使用一个包或添加导入AsteroidField.Asteroid;在AsteroidField中,我想。
答案 1 :(得分:0)
重新检查所有类中的包声明!
在NetBeans中观察到此行为,当包的某个类中的包声明引用不存在或错误的包时。 NetBeans通常会检测并突出显示此错误,但已知失败并误导性地报告包没有错误,但事实并非如此。