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
Regular Contributor
Posts: 92
Registered: ‎01-31-2012
My Device: curve 8520
My Carrier: vodafone

deploying on real device

[ Edited ]

Hi guys,my application is working well on the simmulator but it'snot working on the real device the splash screen is started and stopped  with no progress that's the  code of the splash screen

 

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
public class SplashScreen extends MainScreen {

	String url = "http://www.myURL.com/file.xml";

	public SplashScreen() {
		setTitle("loading...");

		Thread threadToRun = new Thread() {
			public void run() {
				// First, display this screen

				// // Now run the code that must be executed in the Background
				try {
					new Connection(url, "categories");
				} catch (Throwable t) {
					t.printStackTrace();
					throw new RuntimeException(
							"Exception detected while waiting: " + t.toString());
				}
				// Now dismiss this screen
				UiApplication.getUiApplication().invokeLater(new Runnable() {
					public void run() {
						UiApplication.getUiApplication().pushScreen(
								new MyScreen());
						close();

					}
				});
			}
		};
		threadToRun.start();

	}
}

 

and the connection class

 

import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.xml.parsers.ParserConfigurationException;
import net.rim.device.api.xml.parsers.SAXParser;
import net.rim.device.api.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class Connection {
	private String url, type;

	public Connection(final String url, final String type) {
		this.type = type;
		this.url = url;
		getData();
	}

	public void getData() {
		InputStream inputStream = null;
		HttpConnection httpConnection = null;
		try {
			httpConnection = (HttpConnection) Connector.open(url);

			if (httpConnection.getResponseCode() == HttpConnection.HTTP_OK) {
				System.out.println("heeeeeeeeeeeeeeeeey 			connection");
				inputStream = httpConnection.openDataInputStream();
				String desiredEncoding = "ISO-8859-1"; // iso-8859-1
				String contenttype = httpConnection
						.getHeaderField("Content-Type");
				if (contenttype != null) {
					contenttype = contenttype.toUpperCase();
					if (contenttype.indexOf("UTF-8") != -1) {
						desiredEncoding = "UTF-8";
					}
				}
				InputSource is = new InputSource(inputStream);
				is.setEncoding(desiredEncoding);
				SAXParserFactory factory = SAXParserFactory.newInstance();
				SAXParser parser = factory.newSAXParser();
				if (type.equalsIgnoreCase("categories")) {
					CatHandler myHandler = new CatHandler();
					parser.parse(is, myHandler);
				} else if (type.equalsIgnoreCase("items")) {
					ItemsHandler itemHandler = new ItemsHandler();
					parser.parse(is, itemHandler);
				}

			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.out.println("it'snot working..." + e.getMessage());
			Dialog.inform("it'snot working");
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			System.out.println("it'snot working..." + e.getMessage());
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			System.out.println("it'snot working..." + e.getMessage());
		}

	}
}

 

please tell me guys how can I solve that ?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: deploying on real device

I think you will find that your networking code is not working, throwing an IOException, and then in there you attempt to do a Dialog, but the Thread is not running on the Event Thread and this will fil with an Illiegal State. 

 

But the best thing to do is to try to debug on device and step through your processing:

http://supportforums.blackberry.com/t5/Java-Development/How-Do-I-Debug-on-a-Live-Device/ta-p/446842

 

Regular Contributor
Posts: 92
Registered: ‎01-31-2012
My Device: curve 8520
My Carrier: vodafone

Re: deploying on real device

actually it stops on line
httpConnection = (HttpConnection) Connector.open(url); in class connection without any exception just stop !
Developer
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: deploying on real device

Can you clarify one thing,

Are you adding ConnectionSuffix to the main URL?

 

 

Regular Contributor
Posts: 92
Registered: ‎01-31-2012
My Device: curve 8520
My Carrier: vodafone

Re: deploying on real device

sorry I don't understand what you are saying ?
Developer
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: deploying on real device

When you going to run your app in device you need to append some connection suffix to your main URL,

 

See this link,

 

http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-make-an-HTTP-or-socket-con...

 

Thanks.

Regular Contributor
Posts: 92
Registered: ‎01-31-2012
My Device: curve 8520
My Carrier: vodafone

Re: deploying on real device

I have edited the connection to that

StreamConnection s = null;
s = (StreamConnection) Connector.open(url);
HttpConnection httpConn = (HttpConnection) s;

but the problem isn't in the suffix , it stops for no reasons
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: deploying on real device

"actually it stops on line
httpConnection = (HttpConnection) Connector.open(url); in class connection without any exception just stop !"

 

I can state with high confidence that it does NOT stop on that line.

 

Can you change the code so that you catch all Exceptions, put break points after this line and in all the Catch code (on the System.out.., ) and wait.  Tell us what happens.

 

Could you also give us your complete URL (change any incriminating parts to "x").

Regular Contributor
Posts: 92
Registered: ‎01-31-2012
My Device: curve 8520
My Carrier: vodafone

Re: deploying on real device

yeah right this message appears
int the IOExceiption

".APN is not specified."
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: deploying on real device

Time to learn some networking then

 

Put network in the Search box and review the Networking videos you will find.  Then have a look at this:

http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-make-an-HTTP-or-socket-con...

 

If you are running in OS 5.0 and above, then look at the JavaDoc for ConnectionFactory, as it is an easier option than coding your own suffixes. 

 

Once you have been through this lot, then you should be able to figure out what has caused the exception and how to fix it.