BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 05-15-2008, 06:23 AM   #1
ahmadgee
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: do not know
Posts: 51
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 06:25 AM..
Offline  
Old 05-15-2008, 06:43 AM   #2
jfisher
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Default

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));
}
});
}
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!

Last edited by jfisher; 05-15-2008 at 07:17 AM..
Offline  
Old 05-15-2008, 07:05 AM   #3
ahmadgee
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: do not know
Posts: 51
Default

Quote:
Originally Posted by jfisher View Post
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
Offline  
Old 05-15-2008, 09:47 AM   #4
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

Code:
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();			
sp.parse(in, new XMLHandler());
with XMLHandler extending DefaultHandler.
__________________
java developer, Devinto, hamburg/germany
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Motorola 68060 68EC060 MC68EC060RC75 CPU / Processor AMIGA unused, new USA stock picture

Motorola 68060 68EC060 MC68EC060RC75 CPU / Processor AMIGA unused, new USA stock

$69.99



New Greaseweazle V4.1 USB Floppy Adapter Flux Reader Writer Amiga 1591 picture

New Greaseweazle V4.1 USB Floppy Adapter Flux Reader Writer Amiga 1591

$28.31



[1pcs] 8520A-1 MOS 8520A-1  Commodore Amiga DIP40 USED picture

[1pcs] 8520A-1 MOS 8520A-1 Commodore Amiga DIP40 USED

$15.07



New Tank Mouse White Beige USB Wireless Bluetooth 5.0 Amiga PC C64 1283 picture

New Tank Mouse White Beige USB Wireless Bluetooth 5.0 Amiga PC C64 1283

$56.67



Camera for Laser Engraving Machine picture

Camera for Laser Engraving Machine

$156.01



Camera Precise Positioning Support Video Record for Acmer Laser Engraving picture

Camera Precise Positioning Support Video Record for Acmer Laser Engraving

$150.78







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.