当我尝试运行此代码时,我一直收到此错误"线程'主要'中的例外情况java.lang.NoClassDefFoundError:main"。谁能帮我吗?这是我的代码。此外,我必须使用缓冲读取器来读取输入,但我无法弄清楚如何实现我已经拥有的。任何帮助都会很棒!
import java.util.Arrays;
public class StatPackage {
private int i, numScores, place;
private double sum, mean, median, sumOfSquares, variance, stdDev;
private double [] inputs;
private double [] reducedArray;
private int [] histogramArray;
private final int MAX = 500;
//constructor
public StatPackage(){
inputs = new double[MAX]; //creates array
numScores = 0; // count is 0
histogramArray = new int[MAX];
}
public void Histogram(){
//histogramArray = Arrays.copyOf(inputs, MAX);
for (i = 0; i < numScores; i++){
//place = (int)(inputs[i]/10);
if (inputs[i] > 0 && inputs[i] <= 10){ histogramArray[0]+=1;}
if (inputs[i] > 10 && inputs[i] <= 20){ histogramArray[1]+=1;}
if (inputs[i] > 20 && inputs[i] <= 30){ histogramArray[2]+=1;}
if (inputs[i] > 30 && inputs[i] <= 40){ histogramArray[3]+=1;}
if (inputs[i] > 40 && inputs[i] <= 50){ histogramArray[4]+=1;}
if (inputs[i] > 50 && inputs[i] <= 60){ histogramArray[5]+=1;}
if (inputs[i] > 60 && inputs[i] <= 70){ histogramArray[6]+=1;}
if (inputs[i] > 70 && inputs[i] <= 80){ histogramArray[7]+=1;}
if (inputs[i] > 80 && inputs[i] <= 90){ histogramArray[8]+=1;}
if (inputs[i] > 90 && inputs[i] <= 100){ histogramArray[9]+=1;}
}
System.out.print(" 1 - 10 | ");
for (i = 0; i < (histogramArray[0]/5); i++){
System.out.print("*");
}
System.out.println();
System.out.print("11 - 20 | ");
for (i = 0; i < (histogramArray[1]/5); i++){
System.out.print("*");
}
System.out.println();
System.out.print("21 - 30 | ");
for (i = 0; i < (histogramArray[2]/5); i++){
System.out.print("*");
}
System.out.println();
System.out.print("31 - 40 | ");
for (i = 0; i < (histogramArray[3]/5); i++){
System.out.print("*");
}
System.out.println();
System.out.print("41 - 50 | ");
for (i = 0; i < (histogramArray[4]/5); i++){
System.out.print("*");
}
System.out.println();
System.out.print("51 - 60 | ");
for (i = 0; i < (histogramArray[5]/5); i++){
System.out.print("*");
}
System.out.println();
System.out.print("61 - 70 | ");
for (i = 0; i < (histogramArray[6]/5); i++){
System.out.print("*");
}
System.out.println();
System.out.print("71 - 80 | ");
for (i = 0; i < (histogramArray[7]/5); i++){
System.out.print("*");
}
System.out.println();
System.out.print("81 - 90 | ");
for (i = 0; i < (histogramArray[8]/5); i++){
System.out.print("*");
}
System.out.println();
System.out.print("91 - 100 | ");
for (i = 0; i < ((histogramArray[9]/5) + (histogramArray[10]/5)); i++){
System.out.print("*");
}
System.out.println();
}
//go through each value of reducedArray, find out what numbers it is between, and increment array value by 1.
// so if the test score is 35, increment reducedArray[3] by 1. then, divide each array index by 5, print that number of stars.
//insert scores into inputs array
public void insert (double val){
if (numScores < MAX){
inputs[numScores] = val;
numScores++;
reducedArray = Arrays.copyOf(inputs, numScores);
}
}
double Mean() {
for (i = 0; i < numScores; i++){
sum += reducedArray[i];
}
mean = (sum/numScores);
return mean;
}
double Median(){
Arrays.sort(reducedArray);
double num1 = reducedArray[(numScores/2)];
double num2 = reducedArray[((numScores/2)-1)];
if (numScores % 2 == 0){
median = ((num1 + num2)/2);
}
if (numScores % 2 != 0){
median = reducedArray[(numScores/2)];
}
return median;
}
double Variance(){
sum = 0;
for (i = 0; i < MAX; i++){
sumOfSquares += (inputs[i]*inputs[i]);
}
for (i = 0; i < MAX; i++){
sum = sum + inputs[i];
}
variance = ((sumOfSquares/numScores) - (sum * sum)/(numScores * numScores));
return variance;
}
double StdDev (double varianceinput){
stdDev = Math.sqrt(varianceinput);
return stdDev;
}
}
答案 0 :(得分:1)
你的班级没有主要方法。作为第一步,尝试添加以下内容:
public static void main(String[] args) {
final StatPackage statPackage = new StatPackage();
statPackage.Histogram();
}
主要方法是Java的切入点。每个可执行的Java程序都需要一个。
答案 1 :(得分:0)
线程“main”中的异常java.lang.NoClassDefFoundError: 首先检查你的班级名称和保存的文件名是否相同? 不等于这两个名字你可以得到上面的错误。 记住这些名称区分大小写。 例如: - 保存文件名 - t est.java 类名: T \ test.java(在textpad中) 那么你可以得到以上错误。