我有以下解析代码
public class XML_Parsing_Sample extends UiApplication{
//creating a member variable for the MainScreen
MainScreen _screen= new MainScreen();
//string variables to store the values of the XML document
String _node,_element;
Connection _connectionthread;
public static void main(String arg[]){
XML_Parsing_Sample application = new XML_Parsing_Sample();
//create a new instance of the application
//and start the application on the event thread
application.enterEventDispatcher();
}
public XML_Parsing_Sample() {
_screen.setTitle("XML Parsing");//setting title
_screen.add(new RichTextField("Requesting....."));
_screen.add(new SeparatorField());
pushScreen(_screen); // creating a screen
//creating a connection thread to run in the background
_connectionthread = new Connection();
_connectionthread.start();//starting the thread operation
}
public void updateField(String node, String element) {
synchronized (UiApplication.getEventLock()) {
String title = "My App";
_screen.add(new RichTextField(node + " : " + element));
if (node.equals(title)) {
_screen.add(new SeparatorField());
}
}
}
private class Connection extends Thread{
public Connection(){
super();
}
public void run(){
// define variables later used for parsing
Document doc;
StreamConnection conn;
try{
conn=(StreamConnection)Connector.open
("http://www.islamicfinder.org/prayer_service.php?" +
"country=united_arab_emirates&city=abu_dhabi&state=01&zipcode=&latitude" +
"=24.4667&longitude=54.3667&timezone=4&HanfiShafi=1&pmethod=4&fajrTwilight1=" +
"10&fajrTwilight2=10&ishaTwilight=10&ishaInterval=30&dhuhrInterval=1&" +
"maghribInterval=1&dayLight=0&simpleFormat=xml&monthly=1&month=");
_screen.add(new RichTextField("connn---"+conn));
DocumentBuilderFactory docBuilderFactory
= DocumentBuilderFactory. newInstance();
DocumentBuilder docBuilder
= docBuilderFactory.newDocumentBuilder();
docBuilder.isValidating();
doc = docBuilder.parse(conn.openInputStream());
doc.getDocumentElement ().normalize ();
NodeList list=doc.getElementsByTagName("prayer");
_node=new String();
_element = new String();
for (int i=0;i<list.getLength();i++){
Node value=list.item(i).
getChildNodes().item(0);
_node=list.item(i).getNodeName();
_element=value.getNodeValue();
updateField(_node,_element);
}
}
catch (Exception e){
System.out.println(e.toString());
}
}
}
}
但是当我运行这个应用程序时,模拟器只是向我显示一个带有标签的空白屏幕Requesting..
有人可以帮我做这件事吗?我正在使用 bb9900 模拟器。