开发者

Android : Nested if statements jump between statements

开发者 https://www.devze.com 2023-02-06 18:23 出处:网络
In my Android application I am trying to read an xml file using XMLPullParser using the following code:

In my Android application I am trying to read an xml file using XMLPullParser using the following code:

while (eventType != XmlPullParser.END_DOCUMENT) 
                {
                    if (eventType == XmlPullParser.START_TAG) 
                    {
                        s = xpp.getName();
                        if (xpp.getName().equalsIgnoreCase("container"))
                        {
                            state = stateContainer;
                            con = new Container();
                            con.setId(xpp.getAttributeValue(0));
                            con.setParentId(xpp.getAttributeValue(1));
                            con.setRestricted(xpp.getAttributeValue(2));
                        }
                        else if (xpp.getName().equalsIgnoreCase("title")) 
                        {
                            state = stateTitle;
                        } 
                        else 
                        {
                            state = stateUnknown;
                        }
                    } 
                    else if (eventType == XmlPullParser.TEXT) 
                    {
                        s = xpp.getText();
                        if (state == stateTitle) 
                        {
                            con.setTitle(s);
                        }
                    } 
                    else if (eventType == XmlPu开发者_运维技巧llParser.END_TAG) 
                    {
                        s = xpp.getText();
                        if (xpp.getText().equalsIgnoreCase("container")) 
                        {
                            listAdapter.add(con);
                        }
                    }
                    eventType = xpp.next();
                }

However, it seems to jump into the line 'listAdapter.add(con);' when none of the other if clauses are true in the other if statements. For example:

else if (eventType == XmlPullParser.TEXT) returns true. It then tries if (state == stateTitle) which returns false. It should jump to eventType == xpp.next(); but instead goes to listAdapter.add(con); which is nested in a different if statement. This also happens with some other if statements.

I would say I'm no beginner when it comes to programming but I can not seem to work out where this problem is coming from!

Thanks


There is no magic.

If, while debugging you see the control flow acting as you describe it, then it seems likely that the code you are executing does not match the source. Try doing a clean and a full rebuild.

0

精彩评论

暂无评论...
验证码 换一张
取 消