Java 解析字符串表中的输入
嗨,我有这部分代码,我想用一些输入创建一个字符串表,但我得到了这个错误Java 解析字符串表中的输入,java,Java,嗨,我有这部分代码,我想用一些输入创建一个字符串表,但我得到了这个错误 Exception in thread "main" java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Integer.java:417) at java.lang.Integer.parseInt(Integer.java:499) 这是我的密码 String[] temp2 = nul
Exception in thread "main" java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:417)
at java.lang.Integer.parseInt(Integer.java:499)
这是我的密码
String[] temp2 = null;
temp2 = dog1.lineDelimiter(resultdog1[0], 6, "#"); // spaei se 6 strings
dog1.setId(temp2[0]);
dog1.Posotita=Integer.parseInt(temp2[1]);
dog1.Price=Double.parseDouble(temp2[2]);
dog1.setPerigrafi(temp2[3]);
dog1.Size=Integer.parseInt(temp2[4]);
dog1.setRatsa(temp2[5]);
String lastPelatis=itm.LastInput("Pelates.txt");
String[] tempPel = null;
tempPel = dog1.lineDelimiter(lastPelatis, 6, "#"); // spaei se 6 strings
pel.setUserName(tempPel[0]);
pel.setPassword(tempPel[1]);
pel.setAdress(tempPel[2]);
pel.setFName(tempPel[3]);
pel.setLName(tempPel[4]);
pel.setTelephone(tempPel[5]);
String[] timologio;
timologio = new String[12];
timologio[0] = tempPel[0];
timologio[1] = tempPel[2];
timologio[2] = tempPel[3];
timologio[3] = tempPel[4];
timologio[4] = tempPel[5];
timologio[5]="//";
dog1.setId(timologio[6]);
dog1.Posotita=Integer.parseInt(timologio[7]);
dog1.Price=Double.parseDouble(timologio[8]);
dog1.setPerigrafi(timologio[9]);
dog1.Size=Integer.parseInt(timologio[10]);
dog1.setRatsa(timologio[11]);
timologio[0]=pel.toString();
您正在尝试解析非整数的内容。你能看看你为
parseInt
函数提供了什么,并确保它真的是一个数字吗?我建议你在parseInt和parseDouble语句中加入try/catch和catch NumberFormatException
比如说,
try {
dog1.Posotita=Integer.parseInt(timologio[7]);
} catch (NumberFormatException e) {
if (null == timologio[7]) System.err.println("timologio[7] is null!");
else System.err.println("Cannot parse timologio[7] of <" + timologio[7] + ">");
timologio[7] = Integer.MIN_VALUE; // or other error of your choice
}
试试看{
dog1.Posotita=Integer.parseInt(timologio[7]);
}捕获(数字格式){
if(null==timogio[7])System.err.println(“timogio[7]为null!”);
else System.err.println(“无法解析timologio[7]of”);
Timogio[7]=Integer.MIN_VALUE;//或您选择的其他错误
}
您可以指定要传递给字符串[]的内容吗?您的强制转换可能不正确,因为它是null
。timologio
的元素不是从索引6开始初始化的。它是从何处开始的?我怎样才能做我想要的绳子?