0

我已经在我的代码中加入了祝酒词,并弄清楚了似乎是什么方法导致了这个问题,但我无法弄清楚为什么。根本没有编译错误,但程序似乎没有完成这个方法。

在此之后它继续工作,它只是完全跳过一个部分并将某些变量保留为空,导致它稍后在代码中跳过操作。

我最终试图从数据库中提取最后一个条目,比较数字并根据两组之间的差异进行计算。如果我的数据对象为空,我将代码设置为不进行计算,并且由于这个问题,我的数据对象始终为空。

我已将 Toast 通知放在此代码中的多个位置,它似乎卡在while循环中的某个地方。

private Flows readFlows(XmlPullParser parser) throws XmlPullParserException, IOException
        {
            parser.require(XmlPullParser.START_TAG, null, "flows");

            //declare variables
            String ReportDate = null;
            String TimeMeterRead = null;
            Integer Influent14 = null;
            Integer Influent15 = null;
            Double WaterTreated14 = null;
            Double WaterTreated15 = null;
            Double TotalWaterTreated = null;
            Integer Softener1 = null;
            Double WaterSoftened1 = null;
            Integer Softener2 = null;
            Double WaterSoftened2 = null;
            Integer Softener3 = null;
            Double WaterSoftened3 = null;
            Integer Softener4 = null;
            Double WaterSoftened4 = null;
            Integer Softener5 = null;
            Double WaterSoftened5 = null;
            Integer WaterByPassed = null;
            Double TotalByPassed = null;
            Double SaltUsed = null;
            Double SoftenerRegeneration = null;
            Double RegenWaste = null;
            Double Level = null;
            Double PSI = null;

            //read tag and open corresponding function
            while(parser.next() != XmlPullParser.END_TAG)
            {
                if (parser.getEventType() != XmlPullParser.START_TAG)
                {
                    continue;
                }
                String name = parser.getName();
                if (name.equals("ReportDate"))
                {
                    ReportDate = readReportDate(parser);
                } else if (name.equals("TimeMeterRead"))
                {
                    TimeMeterRead = readTimeMeterRead(parser);
                } else if (name.equals("ReportID"))
                {
                    Influent14 = readInfluent14(parser);
                } else if (name.equals("Influent14"))
                {
                    Influent14 = readInfluent14(parser);
                } else if (name.equals("Influent15"))
                {
                    Influent15 = readInfluent15(parser);
                } else if (name.equals("WaterTreated14"))
                {
                    WaterTreated14 = readWaterTreated14(parser);
                } else if (name.equals("WaterTreated15"))
                {
                    WaterTreated15 = readWaterTreated15(parser);
                } else if (name.equals("TotalWaterTreated"))
                {
                    TotalWaterTreated = readTotalWaterTreated(parser);
                } else if (name.equals("Softener1"))
                {
                    Softener1 = readSoftener1(parser);
                } else if (name.equals("WaterSoftened1"))
                {
                    WaterSoftened1 = readWaterSoftened1(parser);
                } else if (name.equals("Softener2"))
                {
                    Softener2 = readSoftener2(parser);
                } else if (name.equals("WaterSoftened2"))
                {
                    WaterSoftened2 = readWaterSoftened2(parser);
                } else if (name.equals("Softener3"))
                {
                    Softener3 = readSoftener3(parser);
                } else if (name.equals("WaterSoftened3"))
                {
                    WaterSoftened3 = readWaterSoftened3(parser);
                } else if (name.equals("Softener4"))
                {
                    Softener4 = readSoftener4(parser);
                } else if (name.equals("WaterSoftened4"))
                {
                    WaterSoftened4 = readWaterSoftened4(parser);
                } else if (name.equals("Softener5"))
                {
                    Softener5 = readSoftener5(parser);
                } else if (name.equals("WaterSoftened5"))
                {
                    WaterSoftened5 = readWaterSoftened5(parser);
                } else if (name.equals("WaterByPassed"))
                {
                    WaterByPassed = readWaterByPassed(parser);
                } else if (name.equals("TotalByPassed"))
                {
                    TotalByPassed = readTotalByPassed(parser);
                } else if (name.equals("SaltUsed"))
                {
                    SaltUsed = readSaltUsed(parser);
                } else if (name.equals("SoftenerRegeneration"))
                {
                    SoftenerRegeneration = readSoftenerRegeneration(parser);
                } else if (name.equals("RegenWaste"))
                {
                    RegenWaste = readRegenWaste(parser);
                } else if (name.equals("Level"))
                {
                    Level = readLevel(parser);
                } else if (name.equals("PSI"))
                {
                    PSI = readPSI(parser);
                } else
                {
                    skip(parser);
                }

            }               

            return new Flows(ReportDate, TimeMeterRead, Influent14, Influent15,
            WaterTreated14, WaterTreated15, TotalWaterTreated, Softener1,
            WaterSoftened1, Softener2, WaterSoftened2, Softener3,
            WaterSoftened3, Softener4, WaterSoftened4, Softener5, WaterSoftened5,
            WaterByPassed, TotalByPassed, SaltUsed, SoftenerRegeneration,
            RegenWaste, Level, PSI);
        }

XML 代码:

<xml><flows>
<TotalWaterTreated>200</TotalWaterTreated>
<ReportDate>6/30/2013</ReportDate>
<TimeMeterRead>0700</TimeMeterRead>
<Influent14>100</Influent14>
<Influent15>100</Influent15>
<WaterTreated14>100</WaterTreated14>
<WaterTreated15>100</WaterTreated15>
<Softener1>100</Softener1>
<WaterSoftened1>100</WaterSoftened1>
<Softener2>100</Softener2>
<WaterSoftened2>100</WaterSoftened2>
<Softener3>100</Softener3>
<WaterSoftened3>100</WaterSoftened3>
<Softener4>100</Softener4>
<WaterSoftened4>100</WaterSoftened4>
<Softener5>100</Softener5>
<WaterSoftened5>100</WaterSoftened5>
<WaterByPassed>200</WaterByPassed>
<TotalByPassed>100</TotalByPassed>
<SaltUsed>10</SaltUsed>
<SoftenerRegen>100</SoftenerRegen>
<RegenWaste>10</RegenWaste>
<Level>10</Level>
<PSI>10</PSI>
</flows></xml>
4

1 回答 1

0

那么代码对我来说看起来不错,很奇怪但是很好,你有没有试过在循环中实际调试和观察解析器对象的值?,在某些情况下,名称可能不等于你想要的,这就是它跳过它的原因,这意味着解析器代码或实际XML中存在错误

于 2013-07-01T21:38:51.837 回答