코드를 완료하고 새로운 문제를 반복해서 시도해 본 결과이 오류를 제거한 것으로 보입니다. 나는 파일을 입력으로 스캔하고 평균, 최대 및 최소값을 검색하는 프로그램을 작성하고 있습니다. 그러나 나는 각 점수에 대해 점수를주고 그 점수가 얼마나 많은지를 세어 봐야하는 코드의 마지막 부분에 문제가 있습니다. 그것은 잘 컴파일하지만 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;
}
}
NoClassDefFoundException이 포함 된 stacktrace를 표시합니다. – rfeak
찾을 수없는 클래스는 무엇입니까? 스레드에서 "기본"java.lang.NoClassDefFoundError가를 스택 추적 –
예외를 제공하십시오 : Exam2 에 의해 발생 : 자바에서 이는 java.net.URLClassLoader $ 1.run (URLClassLoader.java:200) 에서 Exam2 : java.lang.ClassNotFoundException가 .security.AccessController.doPrivileged (네이티브 메소드) at java.net.URLClassLoader.findClass (URLClassLoader.java:188) at java.lang.ClassLoader.loadClass (ClassLoader.java:306) at sun.misc.Launcher $ AppClassLoader.loadClass (Launcher.java:276) at java.lang.ClassLoader.loadClass (ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal (ClassLoader.java:319) – user1174712