0

I've put toasts in through out my code and have figured out what method seems to be causing the issue, but I have not been able to figure out why. There is no compile error at all, but the program just doesn't seem to finish this method.

It continues to work after this point, it just completely skips over a section and leaves certain variables null, causing it to skip actions later on in the code.

I'm ultimately trying to pull the last entry from a database, to compare numbers and make calculations based of the differences between the two sets. I have the code set to not make calculations if my data object is null, and because of this issue my data object is always null.

I have put Toast notifications within this code in multiple locations and it seems to get stuck somewhere within the while loop.

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 Code:

<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>

1 Answer 1

0

Well the code looks fine to me, weird but fine, have you tried actually debugging and watching the values of the parser object while in the loop?, name probably is just not equal to what you want in some cases and that's why its skipping it, that would mean there's an error either in the Parser code or on the actual XML

2
  • I haven't quite gone step by step with the debugging, but I have looked down that route. I'll add the xml file to the question, but I generated the structure from a script so there shouldn't be an issue there.
    – Jim
    Jul 1, 2013 at 21:50
  • I found my issue way down in another part of the code. I somehow deleted a break in the part of the parser that skips over unwanted xml elements. My code is now fixed.
    – Jim
    Jul 1, 2013 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.