0

我正在为我的 Web 应用程序使用 java 和 flex,这些应用程序将用于研究所。如果我的结果是 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";
                    }
4

2 回答 2

4

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

于 2013-03-13T06:38:08.327 回答
0
 if (Integer.parseInt(el2.getAttributes().item(k).getNodeValue())<= 60)

这条线给你带来了问题。您需要编写类似的代码

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

 }else if (Integer.parseInt(
                 el2.getAttributes().item(k).getNodeValue())
                                    <= 60) {
               reAppear = "SM";

      }
于 2013-03-13T06:44:33.693 回答