java 无法编译的源代码 - 错误的树类型错误和找不到符号错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35662679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncompilable source code - Erroneous tree type error and cannot find symbol error
提问by MouseGordon
I was getting "Uncompilable source code - Erroneous tree type" error and "cannot find symbol" error I turned off compile on save and now get cannot find symbol. The area that seems to be breaking it is where I initialize Asteroid() in AsteroidFields generate method, so I feel like my initialization is incorrect but I haven't been able to figure out how.
我收到“无法编译的源代码 - 错误的树类型”错误和“找不到符号”错误我在保存时关闭了编译,现在找不到符号。似乎打破它的区域是我在 AsteroidFields generate 方法中初始化 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);
}
}
回答by Viacheslav Vedenin
I see two problems:
我看到两个问题:
1) May be because, you write:
1)可能是因为,你写:
Asteroid asteroid = new Asteroid();
but Asteroid class hasn't got a default construstor (at least, I not see it in your code)
但是 Asteroid 类没有默认构造函数(至少,我在您的代码中没有看到它)
public Asteroid(int velX, int velY, double rot) {
2) Or may be because you use not same package and not use import in AsteroidField
2) 或者可能是因为你使用了不同的包并且没有在 AsteroidField 中使用导入
package asteroidfield;
...
package AsteroidField;
You should or use one package or add import AsteroidField.Asteroid; in AsteroidField, I think.
您应该或使用一个包或添加 import AsteroidField.Asteroid; 在小行星场,我想。
回答by IqbalHamid
Recheck the package declarations in all your classes!
重新检查所有类中的包声明!
This behaviour has been observed in NetBeans, when the package declaration in one of the classes of the package refers to a non-existent or wrong package. NetBeans normally detects and highlights this error but has been known to fail and misleadingly report the package as free of errors when this is not the case.
这种行为在 NetBeans 中被观察到,当包的一个类中的包声明引用不存在或错误的包时。NetBeans 通常会检测并突出显示此错误,但如果不是这种情况,则会失败并误导性地将包报告为没有错误。