java - 找不到符号[编译器错误]

标签 java find symbols

我已经完成了这个小程序,它尝试构建三角形并计算作业的表面,并且我在 Eclipse 中对其进行了测试,但是当我尝试将其上传到我们的系统时,我收到了 6 个错误,所有错误都是同一类型:

/test/src/math.test/TestTriangleFunctionPublic.java:4: error: cannot find symbol import math.NotATriangleException; ^ symbol: class NotATriangleException

/test/src/math.test/TestTriangleFunctionPublic.java:5: error: cannot find symbol import math.Triangle; ^ symbol: class Triangle location: package math

/test/src/math.test/TestTriangleFunctionPublic.java:45: error: cannot find symbol actual = Triangle.calculateArea(a, b, c); ^ symbol: variable Triangle location: class TestTriangleFunctionPublic

/test/src/math.test/TestTriangleFunctionPublic.java:46: error: cannot find symbol } catch (NotATriangleException e1) { ^ symbol: class NotATriangleException location: class TestTriangleFunctionPublic

/test/src/math.test/TestTriangleFunctionPublic.java:56: error: cannot find symbol actual = Triangle.calculateArea(a, b, c); ^ symbol: variable Triangle location: class TestTriangleFunctionPublic

/test/src/math.test/TestTriangleFunctionPublic.java:57: error: cannot find symbol } catch (NotATriangleException e) { ^ symbol: class NotATriangleException location: class TestTriangleFunctionPublic

这是两个类:

package math;

public class Triangle {
    static double s;
    double surface = 0;
    static double a;
    static double b;
    static double c;

    public double calculateArea(double a, double b, double c) throws NotATriangleException{
        if (a<= 0.0 || b <= 0.0 || c <= 0.0){
            throw new NotATriangleException("Cannot construct Triangle!");
        }
        else if( (a+b)<=c && (a+c)<=b && (b+c)<=a){
            throw new NotATriangleException("Cannot construct Triangle!"); 
        } 

        else {
            s = ((a + b + c)/2);
            surface = Math.sqrt(s * (s - a) * (s - b) * (s - c));
            return surface;
        }

    }
    public double getErgebnis (){
        return surface;
    }
}

和异常类:

package math;

@SuppressWarnings("serial")
public class NotATriangleException extends Exception {
    public NotATriangleException(String message) {
        super(message);
    }
    public NotATriangleException(String message,Throwable throwable) {
        super(message, throwable);
    }
}

我很失望,因为我不知道出了什么问题!

最佳答案

您有一个名为 TestTriangleFunctionPublic 的类。我认为您在 Eclipse 中的同一个 math 包中拥有此类,但是当您上传它时,您将位置更改为名为 math.test 的目录。

关于java - 找不到符号[编译器错误],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14429431/

相关文章:

java - 异步任务 : onPostExecute runs twice?

linux - 如何在 bash 中匹配 `find` 的文件 - 也在子目录中?

string - MATLAB。查找字符串元胞数组的索引,其中所有字符都包含在给定字符串中(不重复)

php - CakePHP 查找返回缺少字段的结果

c - GCC 链接器 : move a symbol in a specified section

Java:SimpleDateFormat 未按所需时区进行格式化

java - java中向两个不同的数组添加元素

java - 找不到符号 Java 错误?

python - matplotlib:将特殊数学符号添加到 xticklabels

java - 在 Netty 中添加对 LLRP 的支持