GordonEndersby
Newbie
Dear all,
Im having problems with a bit of code I knocked up in Java outside of the android environment. As part of a console application it worked fine.
But now Im using it in a Widget Im trying to knock up its not working as I expect it to. The widget is compiling and working on the emulator.
The xml is very short and simple as its generated by an Arduino microcontroler running as a web server with a couple of temperature sensors and an ethernet board.
This is my first stab at Java but have plenty of other programming experience as a web developer in Microsoft world with C# and scripting languages. Ive been banging my head for the last few hours and have probably missed something obvious.
I create the DOM like this:
The XML looks like this:
I then call:
text += getTagValue("time", doc);
To append the value returned to a text string.
Im my console application it returns the text from between the <time> </time> tags. But in the widget it returns null.
Is there some difference in the java implementation within the Android version that is causing this?
Or do I need to cast the NodeValue or the returned String in some way?
Thanks
Gordon
Im having problems with a bit of code I knocked up in Java outside of the android environment. As part of a console application it worked fine.
But now Im using it in a Widget Im trying to knock up its not working as I expect it to. The widget is compiling and working on the emulator.
The xml is very short and simple as its generated by an Arduino microcontroler running as a web server with a couple of temperature sensors and an ethernet board.
This is my first stab at Java but have plenty of other programming experience as a web developer in Microsoft world with C# and scripting languages. Ive been banging my head for the last few hours and have probably missed something obvious.
I create the DOM like this:
Code:
URL url = new URL("http://xxxxxx.xxx");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
Code:
<temp>
<time>18:33 - 14 1 2010</time>
<int>19.12</int>
<ext>3.06</ext>
</temp>
text += getTagValue("time", doc);
To append the value returned to a text string.
Im my console application it returns the text from between the <time> </time> tags. But in the widget it returns null.
Code:
private static String getTagValue(String tag, Document doc) {
Element intElement = (Element) doc.getElementsByTagName(tag).item(0);
return intElement.getNodeValue();
}
Or do I need to cast the NodeValue or the returned String in some way?
Thanks
Gordon