简体   繁体   English

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

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

SentiWord method takes String arguments and uses tagger method to tag a word as verb or noun....etc When I run this code I get " java.lang.StringIndexOutOfBoundsException: String index out of range: -3 ". SentiWord方法使用String参数,并使用tagger方法将单词标记为动词或名词。...等当我运行此代码时,我得到“ java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:-3”。 I know there are similar questions like this, but I am unable to apply them to get rid of exception. 我知道也有类似的问题,但是我无法应用它们摆脱异常。

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);
                ....
                ...
                }

What I am trying: 我正在尝试:

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

But exception doesnt seem to go.Please help. 但是异常似乎没有消失。请帮助。

显然, words[i]的长度比taggedWords[i]尝试出于调试目的同时打印它们,我敢打赌,这就是您所看到的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法解决此问题:java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:54 - I am unable to solve this :java.lang.StringIndexOutOfBoundsException: String index out of range: 54 我不断收到此错误:线程“main”中的异常 java.lang.StringIndexOutOfBoundsException: String index out of range: 28 - I keep getting this error : Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 28 构建成功,但我不断收到“线程“main”中的异常 java.lang.StringIndexOutOfBoundsException: String index out of range: 1&#39; - Build is successful but I kept getting the 'Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1' Java错误java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:0 - Java Error java.lang.StringIndexOutOfBoundsException: String index out of range: 0 “ main” java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:17 - “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 17 java.lang.StringIndexOutOfBoundsException:字符串索引超出范围: - java.lang.StringIndexOutOfBoundsException: String index out of range: java.lang.StringIndexOutOfBoundsException:yuicompressor中的字符串索引超出范围 - java.lang.StringIndexOutOfBoundsException: String index out of range in yuicompressor java.lang.StringIndexOutOfBoundsException:字符串索引超出范围 - java.lang.StringIndexOutOfBoundsException: String index out of range java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:45 - java.lang.StringIndexOutOfBoundsException: String index out of range: 45 java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:1 - java.lang.StringIndexOutOfBoundsException: String index out of range: 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM