0
자바 클래스 할당 작업 중입니다. 이 프로그램은 낙서 게임을 돕기로되어 있습니다. 모든 공식 스크래블 단어를 포함하는 소스 파일 Dictionary.txt
을 사용하고 사용자의 입력을 기반으로 출력 파일 output.txt
을 생성합니다. 테스터를 실행하려고하면 NoClassDefFoundError
이 표시됩니다. 왜 누군가가 나를 알아 내도록 도울 수 있습니까?NoClassDefFoundError 메인 클래스가 누락되었습니다.
단어 목록 클래스 :
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class WordLists
{
ArrayList<String> output;
File inFile;
String word;
Scanner input;
public WordLists(String fileName) throws FileNotFoundException
{
inFile = new File(fileName);
input = new Scanner(inFile);
output = new ArrayList<String>();
}
public ArrayList<String> lengthN(int n)
{
while(input.hasNextLine())
{
word = input.nextLine();
if (word.length() == n)
{
output.add(word);
word = input.nextLine();
}
}
return output;
}
public ArrayList<String> startsWith(int n, char firstLetter)
{
while(input.hasNextLine())
{
word = input.nextLine();
if ((word.length() == n) && (word.charAt(0) == firstLetter))
{
output.add(word);
word = input.nextLine();
}
}
return output;
}
public ArrayList<String> containsLetter(int n, char included)
{
while(input.hasNextLine())
{
word = input.nextLine();
if ((word.length() == n) && (word.contains(String.valueOf(included))))
{
output.add(word);
word = input.nextLine();
}
}
return output;
}
public ArrayList<String> vowelHeavy(int n, int m)
{
int vowels = 0;
while(input.hasNextLine())
{
word = input.nextLine();
if (word.length() == n)
{
for(int i = 0; i < word.length(); i++)
{
if(isVowel(word.charAt(i)) == true)
{
vowels++;
}
}
if (vowels == m)
{
output.add(word);
}
}
word = input.nextLine();
}
return output;
}
public ArrayList<String> multiLetter(int m, char included)
{
while(input.hasNextLine())
{
word = input.nextLine();
if (word.contains(String.valueOf(included)))
{
int occurences = 0;
for(int i = 0; i < word.length(); i++)
{
if(word.charAt(i) == included)
{
occurences++;
}
}
if (occurences == m)
{
output.add(word);
}
}
word = input.nextLine();
}
return output;
}
public boolean isVowel(char c)
{
if(c=='a' || c=='A' || c=='e' || c=='E' || c=='i' || c=='I' || c=='o' || c=='O')
{
return true;
}
else
{
return false;
}
}
}
테스터 등급 : 여기
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class Tester
{
public static void main(String[] args)throws FileNotFoundException
{
WordLists wl;
Scanner in;
int n;
int m;
char firstLetter;
char included;
try
{
wl = new WordLists("dictionary.txt");
}
catch (FileNotFoundException e)
{
System.out.println("file not found");
return;
}
in = new Scanner(System.in);
String outFile = "output.txt";
PrintWriter writer = new PrintWriter(outFile);
System.out.println("Search by length? Enter yes or no");
String response = in.next();
if(response.equals("yes"))
{
System.out.println("Enter word length");
n = in.nextInt();
wl.lengthN(n);
for(String a : wl.output)
{
writer.println(a);
}
writer.close();
}
else
{
System.out.println("Search by length and first letter?");
response = in.next();
}
if(response.equals("yes"))
{
System.out.println("Enter word length");
n = in.nextInt();
System.out.println("Enter the first letter");
firstLetter = in.nextLine().charAt(0);
wl.startsWith(n, firstLetter);
for(String a : wl.output)
{
writer.println(a);
}
writer.close();
}
else
{
System.out.println("Search by length and letter?");
response = in.next();
}
if (response.equals("yes"))
{
System.out.println("Enter word length");
n = in.nextInt();
System.out.println("Enter the letter");
included = in.nextLine().charAt(0);
wl.containsLetter(n, included);
for(String a : wl.output)
{
writer.println(a);
}
writer.close();
}
else
{
System.out.println("Search by number of vowels?");
response = in.next();
}
if(response.equals("yes"))
{
System.out.println("Enter word length");
n = in.nextInt();
System.out.println("Enter the number of vowels");
m = in.nextInt();
wl.vowelHeavy(n, m);
for(String a : wl.output)
{
writer.println(a);
}
writer.close();
}
else
{
System.out.println("Search by number of occurences of a letter?");
response = in.next();
}
if(response.equals("yes"))
{
System.out.println("Enter the number of occurences");
m = in.nextInt();
System.out.println("Enter the letter");
included = in.nextLine().charAt(0);
wl.multiLetter(m, included);
for(String a : wl.output)
{
writer.println(a);
}
writer.close();
}
}
}
입니다 오류가 나는 얻을 :
Exception in thread "main" java.lang.NoClassDefFoundError: Tester/java
Caused by: java.lang.ClassNotFoundException: Tester.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: Tester.java. Program will exit.
감사합니다 :
는 WordLists.java 및 Tester.java을 유지 어디 디렉토리에서 다음을보십시오! '테스터 (Tester) '뒤에'.java'를 잘못 추가 한 것은 나였다. 감사. – user3505003