0

これは重複したスレッドである可能性がありますが、いくつかの複数のスレッドを試した後も問題は解決しません:/

辞書を読み取り、それを使用して復号化を行うこのメソッドがあります。ただし、辞書を読む方法がわかりません。辞書をアセット フォルダーにドラッグ アンド ドロップしてから、このコードを使用しました。

try {
    System.out.println("Dictionary Initialize");
    BufferedReader inputReader;
    FileInputStream fis = new FileInputStream("/assets/dictionary-english.txt");
    BufferedReader dictionary = new BufferedReader(new InputStreamReader(fis));
    String checktext;

    while ((checktext = dictionary.readLine()) != null) {
        dictionaryset.add(checktext);
    }
    System.out.println("Dictionary Successfully Initialized");

} catch (IOException ex) {
    System.out.println("Error! reading!");
}

いくつかのテストの後、try と catch がエラーをキャッチするため、while ループに到達することさえできないことを確認しました。IOExceptionエラーもキャッチしました。これを修正する方法はありますか?ありがとう

これは私のエラーですlogcat

10-06 14:54:50.555: W/System.err(1980): java.io.FileNotFoundException: /assets/dictionary-english.txt (No such file or directory)
10-06 14:54:50.555: W/System.err(1980):     at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
10-06 14:54:50.555: W/System.err(1980):     at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
10-06 14:54:50.555: W/System.err(1980):     at java.io.FileInputStream.<init>(FileInputStream.java:80)
10-06 14:54:50.565: W/System.err(1980):     at java.io.FileInputStream.<init>(FileInputStream.java:132)

編集:使ってみた

AssetManager assetManager = getAssets();

ただし、「タイプ ContextWrapper から非静的メソッド getAssets() への静的参照を作成できません」というエラーが表示されますgetAssets()

================================================== ======================

答え:

BufferedReader dictionary = new BufferedReader(new InputStreamReader(getAssets().open("dictionary-english")));    

このコード行を使用してファイルを取得し、メソッドを削除しstaticて静的参照を作成できない問題を解決しました

eg;   private static String run1(String cipherText){  --> private String run1(String cipherText){
4

0 に答える 0