BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-21-2009, 09:14 AM   #1 (permalink)
New Member
 
newbie_bb's Avatar
 
Join Date: Aug 2009
Model: 8300
PIN: N/A
Carrier: simulator
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default java.io.InterruptedIOException: Local connection timed out after ~ 120000

Please Login to Remove!

Hi All,
I am making a sample program which collects the xml from a link and after parsing it prints the content.

The sample code was picked from the knowledge base. While running program the connection is getting time out.

Here is the sample code

Code:
package com.rim.samples.hello;

import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.xml.parsers.DocumentBuilder;
import net.rim.device.api.xml.parsers.DocumentBuilderFactory;

public class HelloWorld extends UiApplication
{
	public static void main(String[] args)
	{
		
		HelloWorld hello = new HelloWorld();
		hello.parseOnlineData();
		hello.enterEventDispatcher();
	}
	public HelloWorld()
	{
		//display a new screen
		pushScreen(new HelloWorldScreen());
	}
	
	final class HelloWorldScreen extends MainScreen
	{
		public HelloWorldScreen()
		{
			super();
			LabelField title = new LabelField("HelloWorld Sample",
			LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
			setTitle(title);
			add(new RichTextField("Hello World!"));
		}
		public boolean onClose()
		{
			Dialog.alert("Goodbye!");
			System.exit(0);
			return true;
		}
	}
	
	public void parseOnlineData()
	{	
		// define variables later used for parsing
        Document doc;
        StreamConnection conn;

        try{
            //providing the location of the XML file,
            //your address might be different
            conn=(StreamConnection)Connector.open
              ("http : //tekmedia.tekritisoftware. com / news.xml");
            //Please manage the link as i was not able to post link
            
            DocumentBuilderFactory docBuilderFactory
              = DocumentBuilderFactory. newInstance(); 
            DocumentBuilder docBuilder
              = docBuilderFactory.newDocumentBuilder();
            docBuilder.isValidating();
            doc = docBuilder.parse(conn.openInputStream());
            doc.getDocumentElement ().normalize ();
            NodeList list=doc.getElementsByTagName("news9");
            for(int i=0;i<list.getLength();i++)
            {
            	Node item = list.item(i);
            	if(item.getNodeType() != Node.TEXT_NODE)
            	{
            		NodeList itemChilds = item.getChildNodes();
                	for(int j=0;j<itemChilds.getLength();j++)
                	{
                		Node detailNode = itemChilds.item(j);
                		if(detailNode.getNodeType() != Node.TEXT_NODE)
                		{
                			if(detailNode.getNodeName().equalsIgnoreCase("title"))
                			{
                				System.out.println(" ###  title="+getNodeValue(detailNode));
                			}
                			if(detailNode.getNodeName().equalsIgnoreCase("date"))
                			{
                				System.out.println(" ###  date="+getNodeValue(detailNode));
                			}
                			if(detailNode.getNodeName().equalsIgnoreCase("author"))
                			{
                				System.out.println(" ###  author="+getNodeValue(detailNode));
                			}
                			if(detailNode.getNodeName().equalsIgnoreCase("summary"))
                			{
                				System.out.println(" ###  summary="+getNodeValue(detailNode));
                			}
                			if(detailNode.getNodeName().equalsIgnoreCase("dst"))
                			{
                				System.out.println(" ###  dst="+getNodeValue(detailNode));
                			}
                		}
                	}
            	}
            }
        }//end try
        //will catch any exception thrown by the XML parser
        catch (Exception e)
        {
            System.out.println(e.toString());
        }
	}
	
	public String getNodeValue(Node node)
	{
		NodeList nodeList = node.getChildNodes();
		Node childNode = nodeList.item(0);
		return childNode.getNodeValue();
	}
}
I ran the code with debug on. Below is the log printing. I am using the blackberry 8300 simulator (default simulator).



Code:
Starting Hello
Started Hello(121)
Foreground Hello(121)
FocusHistory: Focus gained; App Home Screen; Component net.rim.device.apps.internal.ribbon.launcher.RibbonIconField
FocusHistory: Focus lost; App Home Screen; Component net.rim.device.apps.internal.ribbon.launcher.RibbonIconField
FocusHistory: Focus gained; App Hello; Component net.rim.device.api.ui.component.RichTextField
Refreshing connection on send
Running refresh
Local port: 19780
APN: 'rim.net.gprs'
APN username: 'null'
APN password: 'null'
Connection does not exist
Detected information for 1 GPAK connection(s)
Starting net_rim_bb_simphonebook
Started net_rim_bb_simphonebook(122)
EF: 20 SIZE: -1
JVM: bklt @9678: timer
JVM: bklt @9678: idle 2
JVM: bklt @9678: setTimer 20
SHUTTING DOWN SIM SERVER
Exit net_rim_bb_simphonebook(122)
VM:+GC(F)w=11
VM:-GCt=12,b=1,r=0,g=1,w=11
VM:+CR
VM:TI2Rv=26
VM:TI2Rv=25
VM:TI2Rv=24
VM:TI2Rv=23
VM:TI2Rv=22
VM:TI2Rv=21
VM:TI2Rv=20
VM:TI2Rv=14
VM:TI2Rv=13
VM:TI2Rv=11
VM:TI2Rv=19
VM:TI2Rv=12
VM:TI2Rv=10
VM:TI2Rv=9
VM:TI2Rv=8
VM:TR2Iv=74
VM:TR2Iv=72
VM:TR2Iv=68
VM:TR2Iv=71
VM:TR2Iv=70
VM:TR2Iv=69
VM:TR2Iv=62
VM:TR2Iv=65
VM:TR2Iv=66
VM:TR2Iv=67
VM:TR2Iv=64
VM:TR2Iv=63
VM:TR2Iv=55
VM:TR2Iv=54
VM:-CR=12
JVM: bklt @12341: timer
JVM: bklt @12341: idle 23
JVM: bklt @12341: setTimer 22
VM:IGCSc=0
JVM: bklt @15281: timer
JVM: bklt @15281: idle 23
java.io.InterruptedIOException: Local connection timed out after ~ 120000
VM:+GC(F)w=9
VM:-GCt=8,b=1,r=0,g=1,w=9
VM:+CR
VM:TI2Rv=74
VM:TI2Rv=71
VM:TI2Rv=69
VM:TI2Rv=62
VM:TI2Rv=50
VM:TI2Rv=2
VM:TR2Iv=52
VM:TR2Iv=46
VM:TR2Iv=42
VM:TR2Iv=38
VM:TR2Iv=31
VM:-CR=3
I am not getting enough supporting document over this on forum. Please help me out. In case more information is needed let me know.
__________________

Thanks,
Regards,
Amber
Offline  
Old 08-21-2009, 10:02 AM   #2 (permalink)
New Member
 
newbie_bb's Avatar
 
Join Date: Aug 2009
Model: 8300
PIN: N/A
Carrier: simulator
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi I got this resolved ..
Thanks to Simon at support.blackberry forum ..
Change in code is as follows
String url = "http: // tekmedia.tekritisoftware.com/news.xml";
if (DeviceInfo.isSimulator()){
url=url+";deviceSide=true";
}

conn=(StreamConnection)Connector.open(url);

For more details you can follow llink

http: // supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=55946
__________________

Thanks,
Regards,
Amber
Offline  
Old 08-21-2009, 03:22 PM   #3 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

If you run the MDS simulator, your original URL will work without the "deviceside=true" parameter. MDS emulates a BES conneciton.

Now, be advised that while you may have solved your simulator problem, this solution is not going to work on most devices/networks that are out there. You will need to provide APN or WAP gateway info for most carriers. This info will also be placed in your connection parameter and appended to your URL.
Offline  
Closed Thread


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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