Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中通过sax解析器解析标记后,在emmulator中显示空值?_Android_Web Services_Saxparser - Fatal编程技术网

在android中通过sax解析器解析标记后,在emmulator中显示空值?

在android中通过sax解析器解析标记后,在emmulator中显示空值?,android,web-services,saxparser,Android,Web Services,Saxparser,我正在通过Sax解析器在android中制作一个Web服务的小应用程序,我的链接是 (我可以显示****、*******的值,但无法在文本视图中显示的值 这是我的sorcs代码 import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class ExampleHandler extends DefaultHand

我正在通过Sax解析器在android中制作一个Web服务的小应用程序,我的链接是 (我可以显示****、*******的值,但无法在文本视图中显示的值
这是我的sorcs代码

import org.xml.sax.Attributes;

import org.xml.sax.SAXException;

import org.xml.sax.helpers.DefaultHandler;





public class ExampleHandler extends DefaultHandler{



        // ===========================================================

        // Fields

        // ===========================================================



        private boolean in_outertag = false;

        private boolean in_innertag = false;

        private boolean in_mytag = false;



        private ParsedExampleDataSet myParsedExampleDataSet = new ParsedExampleDataSet();



        // ===========================================================

        // Getter & Setter

        // ===========================================================



        public ParsedExampleDataSet getParsedData() {

                return this.myParsedExampleDataSet;

        }



        // ===========================================================

        // Methods

        // ===========================================================

        @Override

        public void startDocument() throws SAXException {

                this.myParsedExampleDataSet = new ParsedExampleDataSet();

        }



        @Override

        public void endDocument() throws SAXException {

                // Nothing to do

        }



        /** Gets be called on opening tags like:

         * <tag>

         * Can provide attribute(s), when xml was like:

         * <tag attribute="attributeValue">*/

       @Override

        public void startElement(String namespaceURI, String localName,

                        String qName, Attributes atts) throws SAXException {

                if (localName.equals("outertag")) {

                        this.in_outertag = true;

                }else if (localName.equals("innertag")) {

                        //this.in_innertag = true;
                    String attrValue = atts.getValue("sampleattribute");
                     myParsedExampleDataSet.setExtractedString(attrValue);

                }else if (localName.equals("mytag")) {

                        //this.in_mytag = true;
                    String attrValue = atts.getValue("mytag");
                 myParsedExampleDataSet.setExtractedString1(attrValue);

                }else if (localName.equals("tagwithnumber")) {

                        // Extract an Attribute

                        String attrValue = atts.getValue("thenumber");

                        int i = Integer.parseInt(attrValue);

                        myParsedExampleDataSet.setExtractedInt(i);

                }

        }



        /** Gets be called on closing tags like:

        * </tag> */

        @Override

        public void endElement(String namespaceURI, String localName, String qName)

                        throws SAXException {

                if (localName.equals("outertag")) {

                        this.in_outertag = false;

                }else if (localName.equals("innertag")) {

                       // this.in_innertag = false;

                }else if (localName.equals("mytag")) {

                        //this.in_mytag = false;

                }else if (localName.equals("tagwithnumber")) {

                        // Nothing to do here

                }

        }



        /** Gets be called on the following structure:

         * <tag>characters</tag> */

        @Override

    public void characters(char ch[], int start, int length) {

                if(this.in_mytag){

               myParsedExampleDataSet.setExtractedString1(new String(ch, start, length));

        }

    }

}![enter image description here][1]
import org.xml.sax.Attributes;
导入org.xml.sax.SAXException;
导入org.xml.sax.helpers.DefaultHandler;
公共类ExampleHandler扩展了DefaultHandler{
// ===========================================================
//田地
// ===========================================================
私有布尔in_outertag=false;
_innertag中的私有布尔值=false;
_mytag中的私有布尔值=false;
private ParsedExampleDataSet myParsedExampleDataSet=new ParsedExampleDataSet();
// ===========================================================
//吸气剂和塞特
// ===========================================================
公共ParsedExampleDataSet getParsedData(){
返回此.myParsedExampleDataSet;
}
// ===========================================================
//方法
// ===========================================================
@凌驾
public void startDocument()引发异常{
this.myParsedExampleDataSet=新的ParsedExampleDataSet();
}
@凌驾
public void endDocument()引发异常{
//无事可做
}
/**在开始标记上调用的获取,如:
* 
*当xml类似于以下内容时,可以提供属性:
* */
@凌驾
public void startElement(字符串namespaceURI、字符串localName、,
字符串qName、属性atts)引发异常{
if(localName.equals(“outertag”)){
this.in_outertag=true;
}else if(localName.equals(“innertag”)){
//this.in_innertag=true;
字符串attrValue=atts.getValue(“sampleattribute”);
myParsedExampleDataSet.setExtractedString(属性值);
}else if(localName.equals(“mytag”)){
//this.in_mytag=true;
字符串attrValue=atts.getValue(“mytag”);
myParsedExampleDataSet.setExtractedString1(属性值);
}else if(localName.equals(“tagwithnumber”)){
//提取属性
字符串attrValue=atts.getValue(“编号”);
int i=整数.parseInt(attrValue);
myParsedExampleDataSet.setExtractedInt(i);
}
}
/**在关闭标记上调用的控件,如:
*  */
@凌驾
public void endElement(字符串namespaceURI、字符串localName、字符串qName)
抛出SAX异常{
if(localName.equals(“outertag”)){
this.in_outertag=false;
}else if(localName.equals(“innertag”)){
//this.in_innertag=false;
}else if(localName.equals(“mytag”)){
//this.in_mytag=false;
}else if(localName.equals(“tagwithnumber”)){
//这里没什么可做的
}
}
/**无法在以下结构上调用的获取:
*人物*/
@凌驾
公共无效字符(字符ch[],整数开始,整数长度){
if(此.in_mytag){
myParsedExampleDataSet.setExtractedString1(新字符串(ch,start,length));
}
}
}![在此处输入图像描述][1]

您在startElement()中注释掉了
this.in_mytag=true
。因此,设置ExtractedString1的characters()函数中的代码块没有执行,因为in_mytag为false


处理mytag开头时还有一件事:
String attrValue=atts.getValue(“mytag”);
是不必要的。它应该在characters()函数中处理(我怀疑您只是为了调试而使用它).

@jason它仍然不起作用,因为我做了您建议我做的更改。有几件事要看。characters()函数是否被调用了?可能会放一个Log.d()语句,其中包含字符的数据以及遇到的最后一个标记。然后用新代码和Log.d输出编辑您的示例。