2016-06-26 7 views
1

ユーザーから文を受け取り、テキストをユーザーに返すプログラムを作成しようとしています。スレッド "main"の例外java.lang.NoClassDefFoundError:net/arnx/jsonic/JSONException

私は自分のアプリケーションを実行すると、私はこのエラーを取得する:これは私がjsonicダウンロードして自分のアプリケーションにjarファイルとしてそれを追加する必要が

Exception in thread "main" java.lang.NoClassDefFoundError: net/arnx/jsonic/JSONException

ということですか?

import java.util.ArrayList; 
import com.cybozu.labs.langdetect.Detector; 
import com.cybozu.labs.langdetect.DetectorFactory; 
import com.cybozu.labs.langdetect.Language; 
import java.util.Scanner; 

import com.cybozu.labs.langdetect.LangDetectException; 

public class LangDetectSample { 
    public void init(String profileDirectory) throws LangDetectException { 
     DetectorFactory.loadProfile(profileDirectory); 
    } 

    public String detect(String text) throws LangDetectException { 
     Detector detector = DetectorFactory.create(); 
     detector.append(text); 
     return detector.detect(); 
    } 

    public ArrayList detectLangs(String text) throws LangDetectException { 
     Detector detector = DetectorFactory.create(); 
     detector.append(text); 
     return detector.getProbabilities(); 
    } 

    public static void main(String[] args) throws LangDetectException { 
     LangDetectSample detector = new LangDetectSample(); 
     Scanner scanner = new Scanner(System.in); 
     System.out.print("Enter text: "); 
     String input = scanner.nextLine(); 
     String language = detector.detect(input); 
     System.out.print(language); 
    } 
} 
+1

'NoClassDefFoundError'は通常、クラスパスから実行時にライブラリが欠けていることを意味します。 –

+0

ここで必要なセクションをお読みください。あるいは、Maven/Gradleを使って依存関係を管理することもできます。 https://github.com/shuyo/language-detection/blob/wiki/ProjectHome.md –

+0

これは素晴らしいcricket_007ありがとう、以前この言語識別ライブラリを使用しましたか? – karir

答えて

2

NoClassDefFoundErrorあなたのクラス定義がコンパイル時に存在している場合はどうなりますが、実行時に欠落しています。定義を含むライブラリをプログラムに提供する必要があります。

これを行うには、通常、プログラムの横にライブラリを配置する必要があります。ライブラリがプログラムの検索場所であるからです。

+0

この場合、net/arnx/jsonic/JSONExceptionが見つかりませんか? – karir

+0

net/arnx/jsonic/JSONExceptionはおそらくあなたのライブラリであるjarファイルの中にあります。 – Shiro

関連する問題