Reputation: 37
I'm using java and flex for my web application which will be used for institutes.
If my result is mark then, less than 60 will be Re Appear RA. For grade system, U will Re Appear. But I'm facing NumberFormatException
if result is grade system. Herewith I have attached my code. Please advise on this as soon as possible.
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";
}
Upvotes: 0
Views: 140
Reputation: 31
if (Integer.parseInt(el2.getAttributes().item(k).getNodeValue())<= 60)
This line create problem for you. You need to write code like
if (el2.getAttributes().item(k).getNodeValue()
== "U") {
reAppear = "SG";
}else if (Integer.parseInt(
el2.getAttributes().item(k).getNodeValue())
<= 60) {
reAppear = "SM";
}
Upvotes: 0
Reputation: 22446
Integer.parseInt(..)
produces this exception when the string expression it receives is null or not a valid integer. You have 2 places where you use this call. It looks like your assumptions about the data contained in the XML node are incorrect. Either the node doesn't exist, or its value isn't an integer.
Upvotes: 4