简体   繁体   中英

getDomElement() make my app doesn't work

With some help in this forum I managed to catch an XML to display it on my apk android, so I tried this week-end to grab some "value" like < login > toto < / login > ( here I want to take "toto" to display it on my apk android as (for example if the guy "toto" log in my apk) Hello toto.

So for now to display the whole XML it's okay but once i add this line :

Document doc = xml.getDomElement(task2);

It's doesn't work anymore... my app just stop after few seconds. so there is some part of my code MainActivity.java :

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    GetXmlTask xml = new GetXmlTask(MainActivity.this , "Website"); // get the XML


    xml.execute(); // execute the task

    textview1 = (TextView) findViewById(R.id.textview1);
    textview2 = (TextView) findViewById(R.id.textview2);


    String task2 = xml.doInBackground(sUrl);
    Document doc = xml.getDomElement(task2); // <--- THE BUGGING LINE IS HERE WHEN I DELETE IT MY APK WORKS AGAIN 

there is the method in GetXmlTask.java :

public Document getDomElement(String task) {

 Log.i("TAG2","test01");
 Document doc = null;
 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try{

        DocumentBuilder db = dbf.newDocumentBuilder();

        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(task));
        doc = db.parse(is);
    } 

    catch (ParserConfigurationException e) { 
     Log.e("Error: ", e.getMessage());
     return null;
    } 
    catch (SAXException e) {
        Log.e("Error: ", e.getMessage());
        return null;
    } 
    catch (IOException e) {
     Log.e("Error: ", e.getMessage());
     return null;
    }

 return doc;

}

If someone can help me I spent about half a week-end just on it.. ^^ Thank you !

PS : I got a method return at the end of my code maybe it make me the error :

public void Returnxml(String data){
        textview1.setText(data); 
    }

check JDOM to parse XML to Strings there are a lot of examples to use the document builder and SAX builder, I could put an example but im not very sure about your intentions or what are you trying to do. anyway hope to help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM