Hi every body,
I am trying to read the rss link. My code is working fine as I tested in other way without using thread. When I am using the following way using thread then it displayed the uncaught exception.
Thanks
Best regards,
Code:
public class UsingSax1 extends net.rim.device.api.ui.UiApplication{
public static void main(String[] args){
UsingSax1 instance=new UsingSax1();
instance.enterEventDispatcher();
}
public UsingSax1() {
pushScreen(new UsingSaxScreen1());
}
}
Code:
class UsingSaxScreen1 extends MainScreen{
UsingSaxScreen1() {
setTitle("Using SAX Example");
Thread parseXML=new Thread(new ParseXML1(this));
parseXML.start();
}
public void updateScreen(String xmlstr){
add(new RichTextField(xmlstr));
}
}
Code:
class ParseXML1 implements Runnable{
UsingSaxScreen1 screen;
ParseXML1(UsingSaxScreen1 screen) {
this.screen=screen;
}
public void run(){
String URL = "http://www.andreasstorm.de/index.php?id=314&type=100";
String xmlString="";
DataInputStream dataInputStream=null;
HttpConnection connection=null;
try{
StringBuffer sbuffer = new StringBuffer();
sbuffer.append(URL);
connection = (HttpConnection)Connector.open(sbuffer.toString());
dataInputStream=new DataInputStream(connection.openInputStream());
int ch;
while((ch=dataInputStream.read())!=-1){
xmlString=xmlString+(char)ch;
}
}
catch(IOException ex){
ex.printStackTrace();
}
this.screen.updateScreen(xmlString);
}
}