![](/img/trans.png)
[英]java - Exception in thread “main” java.lang.NumberFormatException: For input string: “” at
[英]Exception in thread “main” java.lang.NumberFormatException: For input string: “33”
class liste
{
int numara;
String ad;
String soyad;
liste sonraki;
}
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new FileReader("C:\\bagli.txt"));
BufferedReader reader = null;
String s;
Scanner klavye = new Scanner(System.in);
listeler mylist = new listeler();
while(br.ready())
{
s=br.readLine();
String[] firstLine = s.split("#");
liste kayıt = new liste();
kayıt.numara = Integer.parseInt(firstLine[0].trim());
kayıt.ad = firstLine[1].trim();
kayıt.soyad = firstLine[2].trim();
mylist.ekle(kayıt);
}
我收到以下錯誤:
Exception in thread "main" java.lang.NumberFormatException: For input string: "33"
在以下行中:
kayıt.numara = Integer.parseInt(firstLine[0].trim());
我不明白為什么會收到此錯誤。
當字符串格式錯誤時,parseInt函數的NumberFormatException錯誤。 解決此問題的最簡單方法是輸出您要解析的確切字符串。 這通常是用做的System.out.println (insertStringVariableHere)。
以我的經驗,錯誤幾乎總是來自引號或數字周圍其他意外字符的額外空格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.