簡體   English   中英

我收到“ java.lang.StringIndexOutOfBoundsException:字符串索引超出范圍:-3”

[英]I am getting “ java.lang.StringIndexOutOfBoundsException: String index out of range: -3 ”

SentiWord方法使用String參數,並使用tagger方法將單詞標記為動詞或名詞。...等當我運行此代碼時,我得到“ java.lang.StringIndexOutOfBoundsException:字符串索引超出范圍:-3”。 我知道也有類似的問題,但是我無法應用它們擺脫異常。

public static String SentiWord(String stri) {
       MaxentTagger tagger = new MaxentTagger("taggers/english-left3words-distsim.tagger");
           String sample=stri;
            sample = sample.replaceAll("([^a-zA-Z\\s])", "");
            String[] words = sample.split("\\s+");
           String taggedSample = tagger.tagString(sample);
            String[] taggedWords = taggedSample.split("\\s+");
           double totalScore = 0;
            SWN3 test = new SWN3();
            for (int i=0; i<taggedWords.length;i++) {   
               String tail = taggedWords[i].substring(words[i].length() + 1);
                ....
                ...
                }

我正在嘗試:

if (words[i].length()>0)   // This line
             tail = taggedWords[i].substring(words[i].length() + 1);

但是異常似乎沒有消失。請幫助。

顯然, words[i]的長度比taggedWords[i]嘗試出於調試目的同時打印它們,我敢打賭,這就是您所看到的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM