gpt4 book ai didi

java - 发生数字格式异常

转载 作者:行者123 更新时间:2023-12-01 18:52:27 26 4
gpt4 key购买 nike

我正在将 java 和 flex 用于我的 Web 应用程序,该应用程序将用于机构。如果我的成绩是mark的话,不到60分就会是Re Appear RA。对于等级系统,U将重新出现。但如果结果是成绩系统,我将面临 NumberFormatException 。我附上了我的代码。请尽快告知。

XMLProcess xp = new XMLProcess();
try {
Document doc = xp.processXml(xml);
Element el = doc.getDocumentElement();
NodeList nl = el.getElementsByTagName("batch");

if (nl != null && nl.getLength() > 0) {
for (int i = 0; i < nl.getLength(); i++) {

Element el1 = (Element) nl.item(i);
NodeList nl1 = el1.getElementsByTagName("student");
String schKey = el1.getAttribute("schkey");
if (nl1 != null && nl1.getLength() > 0) {
for (int j = 0; j < nl1.getLength(); j++) {
String reAppear = "";
String sms = "";
Element el2 = (Element) nl1.item(j);
String studentName = el2.getAttribute("name");
String studentId = el2.getAttribute("id");
String studentKey = el2.getAttribute("key");
sms += "" + studentName + "\n";
sms += "Sem "
+ sem.substring(sem.indexOf("-") + 1, sem.length())
+ " "
+ course
+ "\n";
sms += "" + exam + "\n";

sms += (el2.getAttribute("mrg").equalsIgnoreCase("G")
? "Sub: Grade"
: "Sub: Marks")
+ "\n";
for (int k = 0;
k < el2.getAttributes().getLength();
k++) {
String aName =
el2.getAttributes().item(k).getNodeName();
if (aName.equalsIgnoreCase("key")
|| aName.equalsIgnoreCase("key")
|| aName.equalsIgnoreCase("id")
|| aName.equalsIgnoreCase("name")
|| aName.equalsIgnoreCase("status")
|| aName.equalsIgnoreCase("total")
|| aName.equalsIgnoreCase("percentage")
|| aName.equalsIgnoreCase("mrg")) {
} else {


sms += el2.getAttributes().item(k).getNodeName().substring(
1)
+ ": "
+ (el2.getAttribute("mrg").equalsIgnoreCase("G")
? (el2.getAttributes().item(k).getNodeValue())
: (Integer.parseInt(
el2.getAttributes().item(k).getNodeValue())
< 60
? "RA"
: el2.getAttributes().item(k).getNodeValue()))
+ "\n";

/***Here exception occurs***/ if (Integer.parseInt(
el2.getAttributes().item(k).getNodeValue())
<= 60) {
reAppear = "SM";

}
if (el2.getAttributes().item(k).getNodeValue()
== "U") {
reAppear = "SG";

}

}
}
if (reAppear.equalsIgnoreCase("SM")) {
sms += "RA : FAIL LESS 60 marks. ";
sms += "Meet Principal/Director/HOD";
}
if (reAppear.equalsIgnoreCase("SG")) {
sms += "U - Fail Re Appear. ";
sms += "Meet Principal/Director/HOD";
}

最佳答案

Integer.parseInt(..) 接收到的字符串表达式为 null 或不是有效整数时,会产生此异常。您有 2 个地方可以使用此调用。您对 XML 节点中包含的数据的假设似乎不正确。该节点不存在,或者其值不是整数。

关于java - 发生数字格式异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15378533/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com