我已经完成了我的代码,并找出了导致问题的方法,但我还没弄清楚原因。根本没有编译错误,但程序似乎没有完成此方法。
在此之后它继续工作,它只是完全跳过一个部分并将某些变量留空,导致它稍后在代码中跳过操作。
我最终试图从数据库中提取最后一个条目,比较数字并根据两组之间的差异进行计算。如果我的数据对象为null,我将代码设置为不进行计算,并且由于此问题,我的数据对象始终为null。
我已将此代码中的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>
答案 0 :(得分:0)
那么代码对我来说很好,很奇怪但很好,你在循环中尝试实际调试和观察解析器对象的值吗? name 可能只是不等于你想要在某些情况下,这就是为什么它会跳过它,这意味着在Parser代码或实际的 XML
上会出现错误