-2
public static float getSelectedHeight() {
String selectedHeightValue = (String)heightSpin.getSelectedItem();
if (heightSpin.getSelectedItemPosition() == 0) {
String feets = selectedHeightValue.substring(0,1);
String inches = selectedHeightValue.substring(2,4);
return (float) (Float.parseFloat(feets) * 0.3048) + (float) (Float.parseFloat(inches) * 0.0254);
} else {
return Float.parseFloat(selectedHeightValue);
}
}
錯誤字符串索引出界異常的,我不知道如何解決它。請幫我解決這個問題如何在我的情況下解決StringIndexOutOfBoundsException?
**java.lang.StringIndexOutOfBoundsException: length=2; regionStart=2; regionLength=2**
你知道你的'經驗法則'在Java中錯了嗎?字符串比較必須用'equals'來完成。 – 0xDEADC0DE
@ 0xDEADC0DE謝謝我寫作時很忙。我更新了答案。 :) –