InvalidFormatException Android

时间:2016-08-04 21:27:38

标签: java android exception opennlp

我在此代码中遇到错误,导致模型对象为null并导致应用程序崩溃。它看起来应该有效,但在这种情况下它不会。当我获得" en-sent.bin"的输入流时,此代码在代码的不同部分工作。对于SentenceModel但是使用此POSModel会出现此错误。任何帮助表示赞赏。应该是一个简单的修复。

这是我的代码:

//sets up the part of speech tagger
public POSModel setupPOSTagger() {
    InputStream modelIn = null;
    POSModel model = null;
    try {
        modelIn = context.getResources().openRawResource(R.raw.en_pos_maxent);
        model = new POSModel(modelIn);
    } catch (IOException e) {
        // Model loading failed, handle the error
        e.printStackTrace();
    } finally {
        if (modelIn != null) {
            try {
                modelIn.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return model;
}

堆栈追踪:

08-04 14:15:44.169 12476-12476/com.gigstudios.newssummary W/System.err: opennlp.tools.util.InvalidFormatException: The profile data stream has an invalid format!
08-04 14:15:44.175 12476-12476/com.gigstudios.newssummary W/System.err:     at opennlp.tools.dictionary.serializer.DictionarySerializer.create(DictionarySerializer.java:224)
08-04 14:15:44.175 12476-12476/com.gigstudios.newssummary W/System.err:     at opennlp.tools.postag.POSDictionary.create(POSDictionary.java:293)
08-04 14:15:44.175 12476-12476/com.gigstudios.newssummary W/System.err:     at opennlp.tools.postag.POSTaggerFactory$POSDictionarySerializer.create(POSTaggerFactory.java:151)
08-04 14:15:44.175 12476-12476/com.gigstudios.newssummary W/System.err:     at opennlp.tools.postag.POSTaggerFactory$POSDictionarySerializer.create(POSTaggerFactory.java:147)
08-04 14:15:44.175 12476-12476/com.gigstudios.newssummary W/System.err:     at opennlp.tools.util.model.BaseModel.finishLoadingArtifacts(BaseModel.java:328)
08-04 14:15:44.175 12476-12476/com.gigstudios.newssummary W/System.err:     at opennlp.tools.util.model.BaseModel.loadModel(BaseModel.java:256)
08-04 14:15:44.175 12476-12476/com.gigstudios.newssummary W/System.err:     at opennlp.tools.util.model.BaseModel.<init>(BaseModel.java:179)
08-04 14:15:44.175 12476-12476/com.gigstudios.newssummary W/System.err:     at opennlp.tools.postag.POSModel.<init>(POSModel.java:105)
08-04 14:15:44.175 12476-12476/com.gigstudios.newssummary W/System.err:     at com.gigstudios.newssummary.WordCounter.setupPOSTagger(WordCounter.java:101)
08-04 14:15:44.175 12476-12476/com.gigstudios.newssummary W/System.err:     at com.gigstudios.newssummary.WordCounter.makeSentences(WordCounter.java:53)
08-04 14:15:44.175 12476-12476/com.gigstudios.newssummary W/System.err:     at com.gigstudios.newssummary.Article.<init>(Article.java:19)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     at com.gigstudios.newssummary.ArticleReceiver.receiveNewsArticles(ArticleReceiver.java:89)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     at com.gigstudios.newssummary.ArticleReceiver.<init>(ArticleReceiver.java:37)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     at com.gigstudios.newssummary.MainActivity.fetchNews(MainActivity.java:114)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     at com.gigstudios.newssummary.MainActivity$1.run(MainActivity.java:52)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     at android.os.Handler.handleCallback(Handler.java:746)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     at android.os.Looper.loop(Looper.java:148)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5443)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err: Caused by: org.xml.sax.SAXException: Can't create default XMLReader; is system property org.xml.sax.driver set?
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:156)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     at opennlp.tools.dictionary.serializer.DictionarySerializer.create(DictionarySerializer.java:219)
08-04 14:15:44.176 12476-12476/com.gigstudios.newssummary W/System.err:     ... 21 more

0 个答案:

没有答案