BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   uncaught exception (http://www.blackberryforums.com/developer-forum/129939-uncaught-exception.html)

ahmadgee 05-15-2008 06:23 AM

uncaught exception
 
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);
    }
}


jfisher 05-15-2008 06:43 AM

most likely you're trying to update the display from a background process and this is causing the exception, you can wrap the action like so:

public void updateScreen(String xmlstr){
UiApplication.getUiApplication().invokeLater(new Runnable() {

public void run() {
add(new RichTextField(xmlstr));
}
});
}

ahmadgee 05-15-2008 07:05 AM

Quote:

Originally Posted by jfisher (Post 930563)
most you're trying to update the display from a background process and this is causing the exception, you can wrap the action like so:

public void updateScreen(String xmlstr){
UiApplication.getUiApplication().invokeLater(new Runnable() {

public void run() {
add(new RichTextField(xmlstr));
}
});
}

Bundle of thanks and best regards for your kind help.
Can you give me suggestion that how can I capture the value of xml tags.
I have already in java using SAX simply but in blackberry there is different environment as I spent one day on the previous problem and you solved it in few seconds. Just please give me tips

thanks again

simon.hain 05-15-2008 09:47 AM

Code:

SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();                       
sp.parse(in, new XMLHandler());

with XMLHandler extending DefaultHandler.


All times are GMT -5. The time now is 03:06 PM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.