SentenceModel model = null;
InputStream modelIn = null;
AssetManager assManager = context.getAssets();
try {
modelIn = assManager.open("en-sent.bin");
model = new SentenceModel(modelIn);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (modelIn != null) {
try {
modelIn.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
//initializes sentence detector
SentenceDetectorME sentenceDetector = new SentenceDetectorME(model);
//Stacktrace
08-03 14:25:23.842 27210-27210/com.gigstudios.newssummary W/System.err: java.io.FileNotFoundException: en-sent.bin
08-03 14:25:23.842 27210-27210/com.gigstudios.newssummary W/System.err: at android.content.res.AssetManager.openAsset(Native Method)
08-03 14:25:23.842 27210-27210/com.gigstudios.newssummary W/System.err: at android.content.res.AssetManager.open(AssetManager.java:313)
08-03 14:25:23.842 27210-27210/com.gigstudios.newssummary W/System.err: at android.content.res.AssetManager.open(AssetManager.java:287)
08-03 14:25:23.842 27210-27210/com.gigstudios.newssummary W/System.err: at com.gigstudios.newssummary.WordCounter.makeSentences(WordCounter.java:35)
08-03 14:25:23.842 27210-27210/com.gigstudios.newssummary W/System.err: at com.gigstudios.newssummary.Article.<init>(Article.java:19)
08-03 14:25:23.842 27210-27210/com.gigstudios.newssummary W/System.err: at com.gigstudios.newssummary.ArticleReceiver.receiveNewsArticles(ArticleReceiver.java:87)
08-03 14:25:23.842 27210-27210/com.gigstudios.newssummary W/System.err: at com.gigstudios.newssummary.ArticleReceiver.<init>(ArticleReceiver.java:37)
08-03 14:25:23.842 27210-27210/com.gigstudios.newssummary W/System.err: at com.gigstudios.newssummary.MainActivity.fetchNews(MainActivity.java:114)
08-03 14:25:23.842 27210-27210/com.gigstudios.newssummary W/System.err: at com.gigstudios.newssummary.MainActivity$1.run(MainActivity.java:52)
08-03 14:25:23.843 27210-27210/com.gigstudios.newssummary W/System.err: at android.os.Handler.handleCallback(Handler.java:746)
08-03 14:25:23.843 27210-27210/com.gigstudios.newssummary W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
08-03 14:25:23.843 27210-27210/com.gigstudios.newssummary W/System.err: at android.os.Looper.loop(Looper.java:148)
08-03 14:25:23.843 27210-27210/com.gigstudios.newssummary W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5443)
08-03 14:25:23.843 27210-27210/com.gigstudios.newssummary W/System.err: at java.lang.reflect.Method.invoke(Native Method)
08-03 14:25:23.843 27210-27210/com.gigstudios.newssummary W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
08-03 14:25:23.843 27210-27210/com.gigstudios.newssummary W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-03 14:25:23.843 27210-27210/com.gigstudios.newssummary D/AndroidRuntime: Shutting down VM
08-03 14:25:23.844 27210-27210/com.gigstudios.newssummary E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gigstudios.newssummary, PID: 27210
java.lang.NullPointerException: Attempt to invoke virtual method 'opennlp.tools.sentdetect.SentenceDetectorFactory opennlp.tools.sentdetect.SentenceModel.getFactory()' on a null object reference
at opennlp.tools.sentdetect.SentenceDetectorME.<init>(SentenceDetectorME.java:86)
at com.gigstudios.newssummary.WordCounter.makeSentences(WordCounter.java:50)
at com.gigstudios.newssummary.Article.<init>(Article.java:19)
at com.gigstudios.newssummary.ArticleReceiver.receiveNewsArticles(ArticleReceiver.java:87)
at com.gigstudios.newssummary.ArticleReceiver.<init>(ArticleReceiver.java:37)
at com.gigstudios.newssummary.MainActivity.fetchNews(MainActivity.java:114)
at com.gigstudios.newssummary.MainActivity$1.run(MainActivity.java:52)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
私はこの問題を何時間も修正しようとしており、どこにもいません。上記のコードサンプルモデルでは、常にnullであり、en-sent.binファイルはmodelInオブジェクトに読み込まれていないようです。私のbinファイルは現在資産フォルダにあります。どんな助けでも大歓迎です。あなたが必要InputStream常にnullpointerexceptionを返します
あなたの質問を編集して、例外に関連するJavaスタックトレースを投稿してください。 – CommonsWare
stacktraceを質問に追加してください。 – Julian
@Julianスタックトレースを追加しました。 – Jared