View Single Post
Old 05-15-2008, 07:23 AM   #1 (permalink)
ahmadgee
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: do not know
Posts: 51
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default uncaught exception

Please Login to Remove!

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

Last edited by ahmadgee : 05-15-2008 at 07:25 AM.
Offline   Reply With Quote