我是.net開發人員,剛開始使用Java開發。目標虛擬機發生異常:對於輸入字符串:「1」java.lang.NumberFormatException
br = new BufferedReader(new FileReader(filePath));
while ((sCurrentLine = br.readLine()) != null) {
int vertIdx = sCurrentLine.trim().indexOf(space);
String ver = sCurrentLine.trim().substring(0,vertIdx);
int vrtInt = Integer.parseInt(ver.trim()); // Here is the error
//Code Continues
}
在的Integer.parseInt(ver.trim()),我收到以下異常:
Exception occurred in target VM: For input string: "1"
java.lang.NumberFormatException: For input string: "1"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at kosaraju.Graph.createGraph(Graph.java:75)
at kosaraju.Graph.main(Graph.java:247)
此時執行的,我對sCurretline值爲 「1 4」 和版本是「1」 我無法弄清楚這樣一個小問題。有人可以指出我的代碼中的錯誤嗎?
這裏是我的觀察窗口:
請勿張貼在引號中的例外。使用代碼塊(編輯器上的「{}」按鈕)來保存其格式。也請縮進您的代碼,以便更容易閱讀並查看其片段的範圍。 – Pshemo
你確定在你想分析的字符串中沒有不可打印的字符嗎?嘗試打印每個字符(或最好是它的代碼點)像'System.out.println(Arrays.toString(yourString.chars()。toArray()));' – Pshemo
我得到這個在調試輸出窗口:[65279,49] 。我的字符串的值爲1 – PushCode