java - 调用一个类给我带来问题(坏类 - 类文件包含错误的类)

标签 java

这是我收到的错误:

 airfoilNumber.java:5: error: cannot access airfoil
    private airfoil myAirfoil = new airfoil();
            ^
  bad class file: ./airfoil.class
    class file contains wrong class: airfoil.airfoil
    Please remove or make sure it appears in the correct subdirectory of the classpath.

这是我的主要类(class):

    import java.util.Scanner;

public class airfoilNumber
{
    private airfoil myAirfoil = new airfoil();
    public static void main(String[] args) 
    {
    Scanner numNaca1 = new Scanner(System.in); //make a scanner and prompt user for their desired NACA number
    System.out.println("What is your NACA number?"); //prompt user for NACA number
    int numNaca = numNaca1.nextInt(); //apply the number to numNaca
    new airfoil(numNaca); //call out airfoil class and run calculations


    }
}

这是我的计算器类:

package airfoil;
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class airfoil

{   

    private static final int numOfCoord = 250;
    double dx = 1

.0 / numOfCoord;

private double      m;      // maximum camber in % of chord
private double      p;      // chordwise position of max ord., 10th of chord
private double      t;      // thickness in % of the cord

private String      nacaNum;        // NACA number - 4 digits
private double[][]  coordinates;    // Coordinates of the upper half or lower half of the airfoil
private double[][]  meanLine;       // mean line coordinates

public airfoil(String number) {

    nacaNum = number;
    m = Double.parseDouble(nacaNum.substring(0,1)) / 100.0;
    p = Double.parseDouble(nacaNum.substring(1,2)) / 10.0;
    t = Double.parseDouble(nacaNum.substring(2,4)) / 100.0;

    meanLine = new double[2][numOfCoord];  // x values row 0, y values row 1

    // x upper = row 0, 
    // y upper = row 1,
    // x lower = row 2,
    // y lower = row 3
    coordinates = new double [4][numOfCoord];

    System.out.println("NACA: " + nacaNum);
    System.out.println("Number of coordinates: " + numOfCoord);

    calcMeanLine();
    calcAirfoil();

}

/*
 * Calculates the values for the mean line forward of the maximum
 * ordinate and aft of the maximum ordinate.  
 */
private void calcMeanLine() {

    double x = dx;
    int j = 0;

    // fwd of max ordinate
    while (x <= p) {
        meanLine[0][j] = x;
        meanLine[1][j] = (m / (p * p))*(2*p*x - (x*x));
        x += dx;
        j++;
    }

    // aft of max ordinate
    while (x <= 1.0 + dx) {
        meanLine[0][j] = x;
        meanLine[1][j] = (m / ((1 - p) * (1 - p))) *
                     ((1 - 2*p) + 2*p*x - x * x);
        x += dx;
        j++;
    }
}  // end calcMeanLine

/*
 * Calculate the upper and lower coordinates of the airfoil surface.
 */
private void calcAirfoil() {

    double theta;       // arctan(dy_dx)
    double dy;          // derivative of mean line equation
    double yt, ml;      // thickness and meanline values, respectively
    double x = dx;      // x-value w.r.t. chord
    int j = 0;          // counter for array

    // calculate upper/lower surface coordinates fwd of max ordinate
    while (x <= p) {

        dy = (m / (p*p)) * (2*p - 2*x);
        theta = Math.atan(dy);
        yt = thicknessEQ(x);
        ml = meanLine[1][j];

        // upper surface coordinates;
        coordinates[0][j] = x - yt * Math.sin(theta);
        coordinates[1][j] = ml + yt * Math.cos(theta);

        // lower surface coordinates
        coordinates[2][j] = x + yt*Math.sin(theta);
        coordinates[3][j] = ml - yt * Math.cos(theta);

        x += dx;
        j++;

    }

    // calculate the coordinates aft of max ordinate
    while (x <= 1.0 + dx) {

        dy = (m / ((1 - p) * (1 - p))) * ((2 * p) - (2 * x));
        theta = Math.atan(dy);

        yt = thicknessEQ(x);
        ml = meanLine[1][j];

        // upper surface coordinates;
        coordinates[0][j] = x - yt * Math.sin(theta);
        coordinates[1][j] = ml + yt * Math.cos(theta);

        // lower surface coordinates
        coordinates[2][j] = x + yt * Math.sin(theta);
        coordinates[3][j] = ml - yt * Math.cos(theta);

        x += dx;
        j++;
    }

    System.out.println("j = " + j);

} // end calcAirfoil

/*
 * Thickness equation
 */
private double thicknessEQ(double x) {

    return ((t / 0.2) * (0.2969 * Math.sqrt(x) - (0.126 * x) - 
            (0.3526 * x * x) + (0.28430 * x * x * x) - 
            (0.1015 * x * x * x * x)));
}

public String toString() {

    String str = "";
    NumberFormat df = new DecimalFormat("0.0000");

    System.out.println("Xu\tYu\tXl\tYl");

        for (int j = 0; j < numOfCoord; j++) {
            str += df.format(coordinates[0][j]) + "\t" + 
                   df.format(coordinates[1][j]) + "\t" +
                   df.format(coordinates[2][j]) + "\t" + 
                   df.format(coordinates[3][j]) + "\n";
        }

    return str;
}

/*
 * Return the coordinates array
 */
public double[][] getCoordinates() { return coordinates; }
public int getSize() { return numOfCoord; }

} // end Airfoil class

这是我尝试过的:

将airfoil.class 文件从一个地方移动到另一个地方以使其正常工作

使用“新翼型(””);”就其本身而言,仍然给我同样的错误

使用任何其他类型的代码来调用我的计算器类,同样的错误。

我不知道还要改变什么。我不知道它告诉我关于“错误的类airfoil.airfoil”的信息,这可能会引导我找到解决方案。

我在这里做错了什么?

最佳答案

错误位于:

new airfoil(numNaca); //call out airfoil class and run calculations

删除此行并调用:

myAirfoil(numNaca);

新翼型为您的类创建新实例,而不是运行计算。 代码中存在新实例,请参见行:

private airfoil myAirfoil = new airfoil();

访问它的是 myAirfoil。

关于java - 调用一个类给我带来问题(坏类 - 类文件包含错误的类),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35342138/

相关文章:

java - Spring Boot 单元测试 Autowiring

java - 使用 XSLT 从 xml 文件的父标签和子标签获取值

java - 修复无效标识符的错误

java - OpenGL 变换矩阵无法正确转换

eclipse - 停止 eclipse 添加 @Overide 注释

java - 使用 @PreAuthorize 时 Spring SpelExpression 似乎没有读取我的 bean

java - 使用 gxt 网格时为 "internal compiler exception occurred"

Java进程构建器: environment set correctly but still command not found

java - 共享界面

java - 如何反转 DSpace 中项目 View 的显示顺序?