为什么这个 int 比较失败了?

Why is this int comparison failing?

断点处unparsedString的值:

101010ten十<img src="E58D81.png" />ten, needle21Turn this character 45 degrees either way and you have the x used for the Roman numeral <b>ten</b>.* As a primitive, this character sometimes keeps its meaning of <i>ten</i> and sometimes signifies <i>needle</i>, this latter derived from the kanji for <i>needle</i> (Frame 292). Since the primitive is used in the kanji itself, there is no need to worry about confusing the two. In fact, we shall be following this procedure regularly.Two needles crossing marks the spot, or you can use the Roman character for ten (rotated 45 degrees).I scared away ten vampires with a single cross!15ジュウ、ジッ、ジュッとお、と十分(じっぷん): 10 minutes<br>十字路(じゅうじろ): crossroads<br>五十音(ごじゅうおん): the Japanese syllabary<br>十分(じゅうぶん): enough<br>十(じゅう): 10, ten<br>十(とお): 10, ten<br>十日(とおか): ten days, the tenth day of the month<br>二十歳(はたち): 20 years old, 20th year<br>二十日(はつか): twenty days, twentieth day of the month十字架 (じゅうじか), 十文字 (じゅうもんじ), 十 (と), 十 (とお)

ParseKanji方法:

 protected Kanji parseKanji(String unparsedString) {
    Kanji kanji = new Kanji();
    String[] fields = unparsedString.split("\u001F");

    int onI = findKatakanaIndex(fields); //17 while debugging
    int kunI = onI + 1;  //18, also checked

    kanji.setMeaning(fields[3]);
    kanji.setCharacter(fields[4]);
    kanji.setJH(fields[onI - 2]);
    kanji.setJTPL(fields[onI - 1]);
    kanji.setOnReading(fields[onI]);

    if (fields.length < kunI){ //returns false
    kanji.setKunReading(fields[onI + 1]);
    } else {
    Log.d("MyTests",  fields.length + " < " + kunI);
    Log.d("MyTests",  kanji.getCharacter() + " does not have a kun Reading");
    }

    return kanji;
}

Logcat:

21 < 18
十 does not have a kun Reading

请注意,我之前使用 onI + 1 进行比较,logcat 的输出是:

21 < 171
十 does not have a kun Reading
21 < 18
十 does not have a kun Reading

这是它应该打印的内容。但是您的日志语句是错误的,因为它位于 else 块中,您希望它打印“21 >= 18”。

21 < 171
十 does not have a kun Reading

当您使用 + 运算符时,是否有可能将 17 或 1 表示为字符串?那也会导致这个错误。你可以看到它添加了 17 和 1 来制作“171”而不是 18.