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

Java 调用给我带来问题的类(坏类-类文件包含错误的类),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 appea

下面是我得到的错误:

 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.
这是我的主要课程:

    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
package翼型;
导入java.text.DecimalFormat;
导入java.text.NumberFormat;
公共级机翼
{   
私有静态最终整数NUMOFCORD=250;
双dx=1
.0/纽莫夫库德;
私有双m;//最大拱度,以弦的%为单位
私有双p;//最大值的弦向位置,第10个弦
专用双t;//跳线的厚度(以百分比为单位)
私有字符串nacaNum;//NACA数字-4位
私有双[][]坐标;//机翼上半部分或下半部分的坐标
私有双[][]平均线;//平均线坐标
公共机翼(字符串编号){
nacaNum=数量;
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;
平均线=新的双精度[2][numOfCoord];//x值第0行,y值第1行
//x上限=第0行,
//y上=第1行,
//x下=第2行,
//y下=第3行
坐标=新的双[4][numOfCoord];
System.out.println(“NACA:+nacaNum”);
System.out.println(“坐标数:+numOfCoord”);
calcMeanLine();
跟骨();
}
/*
*计算最大值前的平均线值
*最大纵坐标的纵坐标和纵坐标。
*/
私有void calcMeanLine(){
双x=dx;
int j=0;
//最大纵坐标fwd
而(x误差在:

new airfoil(numNaca); //call out airfoil class and run calculations
删除此行并呼叫:

myAirfoil(numNaca);
新的翼型使你的类的新实例,而不是运行计算。 代码中存在新实例,请参见第行:

private airfoil myAirfoil = new airfoil();

这是我的机翼。

你有以下的等级结构:

package airfoil;

public class airfoil {
   ...
}
这需要像这样反映在文件系统上:

MyProject                     Project's top level directory
    +-airfoilNumber.java
    +-airfoil                 directory for "airfoil" package
        +-airfoil.java
此外,您还需要在
翼型编号
类中导入
翼型。翼型

import airfoil.airfoil;

public class airfoilNumber {
}
通过此设置,您可以使用

C:> javac *.java
作为旁注,类名应该以大写字母开头。我没有回答这个问题,因为
定义与其包含的
文件之间的大小写不匹配。java
文件可能会导致其他难以跟踪的问题,至少在MS Windows上是如此

完成后,您需要修复
翼型
类的构造函数。目前只有一个构造函数接受
字符串
参数,但您可以按如下方式调用它:

private airfoil myAirfoil = new airfoil();   
// does not compile - no non-arg constructor available

...

new airfoil(numNaca);    
// does not compile - numNaca is int, constructor expects String

你已经弄乱了你的目录结构。你的类
aivoril
需要放在一个包中(在文件系统上是一个子目录)
翼型
。它在一个包中。在导入任何东西之前,我将它放在包翼型中的顶部。我没有做对吗?是的,它在一个包中,但也在一个名为翼型的子目录中。你应该将你的类放在一个包中,并使你的类名以大写字母开头。你在问题中读到错误在吗
私人翼型我的翼型=新翼型();
?我不知道paths和他的项目中的其他人有什么问题,我在“新翼型(numNaca);”中看到了明显的错误,仅此而已。是的,“私人翼型我的翼型=新翼型()”仍然存在同样的问题谢谢!包中的主要类是什么?翼型编号?不是翼型?它告诉我包翼型不存在。我在翼型编号中添加了
包翼型
,因为现在它告诉我在“翼型”的每次迭代中都找不到符号在翼型编号类中。否否,您的
翼型编号
类位于默认包中(否
语句)。您必须具有反映包结构的目录结构。(请注意,不鼓励使用默认包,但您现在应该首先关注如何编译当前源代码,然后再修复其他内容).好的,谢谢。它现在编译得很好。我对扫描文件做了一些改动,使其与计算器类相适应,现在编译得很好。计算器类给了我一个问题-
线程“main”java.lang.NoClassDefFoundError中的异常:
,正如您所说,我通过从我的主类中删除包来修复它.现在一切都好了.谢谢你的帮助。
private airfoil myAirfoil = new airfoil();   
// does not compile - no non-arg constructor available

...

new airfoil(numNaca);    
// does not compile - numNaca is int, constructor expects String