简体   繁体   English

从XML中获取值时应用崩溃

[英]App crashing while taking values from XML

I am trying to get url and thumb from the xml by webservice. 我正在尝试通过webservice从xml获取url和thumb。 I am getting the xml but it is crashing while processing the xml. 我正在获取xml,但是在处理xml时崩溃了。

This is my code: 这是我的代码:

String tmpstr = EntityUtils.toString(response.getEntity());
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser xpp = factory.newPullParser();
        xpp.setInput(new StringReader(tmpstr));
        int eventType = xpp.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                if (xpp.getName().toString().equals("url")) {
                    eventType = xpp.nextToken();
                    if (eventType == XmlPullParser.CDSECT) {
                        videourl = videourl + xpp.getText() + ",";
                    }
                } else if (xpp.getName().toString().equals("thumb_image")) {
                    eventType = xpp.nextToken();
                    if (eventType == XmlPullParser.CDSECT) {
                        thumbimage = thumbimage + xpp.getText() + ",";
                    }
                }
            }

            eventType = xpp.next();
        }

I myself have exprerienced many times. 我自己经历了很多次。 when u make any change in the xml and just build your project and run it the app crashes. 当您在xml中进行任何更改并仅构建您的项目并运行它时,应用程序崩溃。 If you clean your code instead of building it your problem of crash should get resolved. 如果您清理代码而不是构建代码,则崩溃问题应得到解决。

尝试使用SAX Parser ...,它更易于使用且速度更快,也可能解决了您的问题.. http://www.java-samples.com/showtutorial.php?tutorialid=152

ok i have resolved the problem. 好的,我已经解决了问题。 It was an XML oriented problem. 这是一个面向XML的问题。

Thanks everyone for all help and comments :) 感谢大家的所有帮助和评论:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检索XML文件时Android应用程序崩溃 - Android App Crashing While Retrieving XML File 拍照后并将结果传送到onActivityResult时,应用程序崩溃 - App crashing after taking picture and while delivering the result to onActivityResult 从 Oneplus 中的相机拍照时应用程序在后台崩溃 - App crashing in background when taking photo from camera in Oneplus 从mysql检索数据时应用崩溃 - App crashing while retrieving data from mysql 从 Firebase Firestore 检索时应用崩溃 - App crashing while retrieving from Firebase Firestore 相机应用程序在 Marshmallow API 23 中运行良好,但是在 API 中拍摄大于 23 的相机时崩溃 - Camera app working fine in Marshmallow API 23, but while taking camera in API grater than 23 is crashing 应用程序因简单的 XML 布局而崩溃 - App crashing with simple XML layout 防止Android应用程序在读取过大的文件时崩溃 - Prevent Android app from crashing while reading a file that is too large 从版本5.0中的收件箱中获取短信时,应用程序崩溃。 在onViewCreated()方法中崩溃 - app crashing while fetching sms from inbox in version 5.0. Crashing in onViewCreated() Method 滚动列表视图时应用崩溃 - App is crashing while scrolling the listview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM