Я прошел через код и снова и снова пробовал новые вещи и не могу избавиться от этой ошибки. Я пишу программу, в которой я просматриваю файл как входной файл, и он просматривает и находит среднее значение, максимальное и минимальное значение. но у меня была апробация к концу кода, где я должен дать оценку для каждого балла, а затем подсчитать, сколько из этих оценок есть. он компилируется отлично, но когда я иду запускать его, java.langNoClassDefFoundError: продолжает идти, пожалуйста, помогите, если сможете.Исключение из потока «main» java.lang.NoClassDefFoundError:
import java.io.*;
import java.util.*;
class Exam
{
public static void main(String [] args) throws IOException
{
int A;
int B;
int C;
int D;
int F;
// Greets user and prompts to enter name of the file containing there grades.
System.out.println("***Welcome to the Exam Statistics Program!!***");
Scanner cin = new Scanner(System.in);
System.out.println("Please enter a filename:");
String filename = cin.next();
// Scanner built for new file and puts grades into an array.
Scanner file = new Scanner(new FileReader(filename));
int g;
g=file.nextInt();
int [] grades = new int[g];
for(int i=0; i<grades.length; i++)
{
grades[i] = file.nextInt();
}
System.out.println("Minimum Score: " + getMinValue(grades));
System.out.println("Maximum Score: " + getMaxValue(grades));
System.out.println("Average Score: " + Average(grades));
System.out.println(" ");
System.out.println(" ");
System.out.println(" ");
System.out.println("A: " +A);
System.out.println("B: " +B);
System.out.println("C: " +C);
System.out.println("D: " +D);
System.out.println("F: " +F);
System.out.println("The grade count is: "+ g);
}
// Calculates the average of the array and returns the variable containing that values.
static double Average(int [] grades)
{
double sum=0;
double x;
for(int i=0; i<grades.length; i++)
sum += (double)grades[i];
if(grades.length==0) return 0;
x = sum/grades.length;
return x;
}
// Calculates the lowest grade in the file.
public static int getMinValue(int[] grades)
{
int minValue = grades[0];
for(int i=1;i<grades.length;i++)
{
if(grades[i] < minValue)
{
minValue = grades[i];
}
}return minValue;
}
// Calculates the highest grade in the file.
public static int getMaxValue(int[] grades)
{
int maxValue = grades[0];
for(int i=1;i < grades.length;i++)
{
if(grades[i] > maxValue)
{
maxValue = grades[i];
}
} return maxValue;
}
// Adds up the total number of letter grades you have in the file.
public static int countA(int[] grades) //throws IOException
{
int A=0;
for(int i=1; i<grades.length;i++)
{
if(grades[i]>89||grades[i]<=100)
{
A = A++;
}
}
return A;
}
public static int countB(int[] grades)
{
int B=0;
for(int i=1; i<grades.length;i++)
{
if(grades[i]>79||grades[i]<=89)
{
B = B++;
}
}
return B;
}
public static int countC(int[] grades)
{
int C = 0;
for(int i=1; i<grades.length;i++)
{
if(grades[i]>69||grades[i]<=79)
{
C = C++;
}
}
return C;
}
public static int countD(int[] grades)
{
int D = 0;
for(int i=1; i<grades.length;i++)
{
if(grades[i]>59||grades[i]<=69)
{
D = D++;
}
}
return D;
}
public static int countF(int[] grades)
{
int F = 0;
for(int i=1; i<grades.length;i++)
{
if(grades[i]<=59)
{
F = F++;
}
}
return F;
}
}
Покажите нам, что stacktrace с NoClassDefFoundException – rfeak
Каков класс, который он не может найти? Пожалуйста, предоставьте трассировки стека –
Исключение в потоке "основной" java.lang.NoClassDefFoundError: Exam2 Вызванный: java.lang.ClassNotFoundException: Exam2 в java.net.URLClassLoader $ 1.Run (URLClassLoader.java:200) на Java .security.AccessController.doPrivileged (собственный метод) на java.net.URLClassLoader.findClass (URLClassLoader.java:188) на java.lang.ClassLoader.loadClass (ClassLoader.java:306) at sun.misc.Launcher $ AppClassLoader.loadClass (Launcher.java:276) в java.lang.ClassLoader.loadClass (ClassLoader.java:251) в java.lang.ClassLoader.loadClassInternal (ClassLoader.java:319) – user1174712