Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 9
Registered: ‎07-31-2009
My Device: Not Specified

Local connection timed out after ~ 120000 while parsing RSS feed with KXML

Hi,

I am getting this error continously while parsing a RSS feed from a site. I dont know how to proceed next.

Here is the code i am using.

 

public HelloWorld()

{

HelloWorldScreen screen =
new HelloWorldScreen();LabelField title = new LabelField("WSJ RSS Sample",LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);

screen.setTitle(title);

 

//add(new RichTextField("Hello World!"));

 

RSSParser parser =
new RSSParser();

//parser.readXml();

screen.add(
new RichTextField(parser.readXml()));//Collecting the out put from the RSS feed

final ObjectListField list = new ObjectListField();

//ObjectListField list = new ObjectListField();

String[] items = new String[] { "Item 1", "Item 2", "Item 3" };

list.set(items);

screen.addMenuItem(
new MenuItem("Select", 100, 1){

public void run(){

int selectedIndex = list.getSelectedIndex();

System.out.println("########### "+selectedIndex+" ############# ");

String item = (String)list.get(list, selectedIndex);

}

});

screen.add(list);

pushScreen(screen);

}

 

 

//Other class RSSParser its content are as follows

Vector itemVector = new Vector(); public String readXml()

{

System.out.println("Moving in read XML ..");HttpConnection hc =

null;

StringBuffer sb = new StringBuffer();

try

{

//RSSParser parser = new RSSParser();

String url = "http://online.wsj.com/xml/rss/3_7011.xml";

hc = (HttpConnection)Connector.open(url);

System.
out.println("Created successfull httepcpnnection for rss.");

parse(hc.openInputStream());

System.
out.println("parse teh system successfully"); for(int i= 0 ; i< itemVector.size() ;i++)

{

Item book = (Item) itemVector.elementAt(i);sb.append(

"\n");sb.append("Title : ");

sb.append(book.getTitle());

sb.append(
"\n");

}

}

catch (IOException ioe)

{

System.
out.println("ioe occurred while connefting and calling parser. Details: "+ioe.getMessage());

}

catch (Exception exception)

{

System.
out.println("Exception occurred while reading xml. Details: "+exception.getMessage());

}

finally

{

try { if (hc != null) hc.close(); } catch (IOException ignored) {}

}

System.out.println(sb.toString());

return sb.toString();

}

 

public void parse(InputStream in) throws IOException

{

System.
out.println("Moving in the parse method for parsing InputStream.");

Reader reader = new InputStreamReader(in);

// XmlPullParser

//XMLParser parser = new XMLParser();

try

{

KXmlParser parser =
new KXmlParser();

parser.setInput(reader);

parser.nextTag();

parser.require(XmlPullParser.
START_TAG, null,"channel");

readXMLData(parser);

parser.require(XmlPullParser.
END_TAG, null, "channel");

parser.next();

parser.require(XmlPullParser.
END_DOCUMENT, null, null);

}

catch (Exception e)

{

System.
out.println("exception occurred while parsing the rss feed. Details:"+e.getMessage());

}

System.
out.println("Moving out of the parse method for parsing InputStream.");

}

 

private void readXMLData(KXmlParser parser) throws IOException, XmlPullParserException

{

System.
out.println("Moving in the readXMLData method with parser.");

//Parse our XML file

parser.require(XmlPullParser.START_TAG, null, "item");

 

Item item =
new Item();

 

while (parser.nextTag() != XmlPullParser.END_TAG) {

 

parser.require(XmlPullParser.
START_TAG, null, null);

String name = parser.getName();

 

String text = parser.nextText();

 

System.
out.println ("<"+name+">"+text);

 

if (name.equals("title"))

item.setTitle(text);

else if (name.equals("link"))

item.setLink(text);

else if (name.equals("description"))

item.setDescription(text);

 

parser.require(XmlPullParser.
END_TAG, null, name);

}

 

itemVector.addElement(item);

 

parser.require(XmlPullParser.
END_TAG, null, "title");

 

System.
out.println("Moving out of the readXMLData method with parser.");

}

 

Thanks,

Regards,

Anand Lal

BlackBerry Development Advisor
Posts: 15,784
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Local connection timed out after ~ 120000 while parsing RSS feed with KXML

What BlackBerry Smartphone model and BlackBerry handheld software version are you testing on?  You can find this under Options, About on the BlackBerry Smartphone.  What route are you connecting over?  What line of code is triggering this error?

 

The default network timeout on a BlackBerry Smartphone is 2 minutes.  So it appears that the application is unable to connect to the destination server.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 78
Registered: ‎12-03-2009
My Device: Not Specified

Re: Local connection timed out after ~ 120000 while parsing RSS feed with KXML

Hey!

Is there any way to change a default connection time out? I mean to increase this value?

thank you in advance!

--
Feel free to press the kudos button on the left side to thank the user that helped you.
Please mark posts as solved if you found a solution.