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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Visitor
Posts: 1
Registered: ‎04-26-2012
My Device: Curve 8520
My Carrier: Claro

Program working on OS 5.0, not in 7.0

I have a problem. I made a program using 5.0 version, and it works fine on emulator of a 8520 curve, and also in the device.

 

Now im trying to use this application on a 9900, with 7.0 version, and it stacks doing an httpconnection in the device. Using my program  5.0 version, in the 9900 emulator, it works fine. Is there any diference between the 2 versions? Im putting the code that i use to make the connection in my thread, but its simple.. I dont know where i can find any answer to this problem.   

 

try {
mTimer = new Timer();
mTimer.schedule(new CountDown(), 60000);

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
popup = new MyPopup("Cargando Incidentes...");
UiApplication.getUiApplication().pushModalScreen(popup);
}
});
conn = (HttpConnection) Connector.open(URL);

InputStream contentIn = conn.openInputStream();
byte[] data = new byte[400];
int length = 0;

StringBuffer raw = new StringBuffer();
while (-1 != (length = contentIn.read(data))) {
raw.append(new String(data, 0, length));
str = raw.toString();



}
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
try {
conn.close();
UiApplication.getUiApplication().invokeLater(new Runnable() {

public void run() {

try {

String datos[] = mainScreen.split(str, "ENDOFPAGE");

datos[0] = datos[0].substring(2, datos[0].length());
mainScreen.vecRegistro = mainScreen.split(datos[0],
"$");
mainScreen.insertoEnBd();
mainScreen.insertoEnTablaDatosBD(_act);

UiApplication.getUiApplication().popScreen(popup);

} catch (Exception e) {
e.printStackTrace();
mainScreen.add(new RichTextField(
"Error ThreadIncidentes.run: "
+ e.toString()));
}

}

});
} catch (IOException e) {

e.printStackTrace();
}



}
});
return;
} catch (Exception e) {

}
}

private class CountDown extends TimerTask {// after 4 seconds
public void run() {
if (str.length() < 50){
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(popup);
Dialog.alert("Error en la conexion");
System.exit(0);


clsThreadIncidentes.currentThread().interrupt();
}
});

return;

}
}
}

Developer
Posts: 125
Registered: ‎08-11-2011
My Device: Blackberry Smartphone 9780
My Carrier: -

Re: Program working on OS 5.0, not in 7.0

[ Edited ]

Sincerelly I not read all of your code, but, I can tell you that you need to open connections, like httpConnections, in a different thread.. because you cant opening a connection in the ui thread.

 

You can use the code template for publish source code. Yours is unreadable.

 

Somebody correct me if I am in a wrong.

---------------------------------------------------------------------

My good english is beceause i dont speak english
Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Program working on OS 5.0, not in 7.0

Looking at your code, I agree that there appears to some issues with the way you do your network processing.

 

I recommend that you look at httpDemo for a sample that uses the standard approach to network processing - i.e. starts a Thread and then waits for that Thread to complete.

 

Let us know how you get one reworking your code around that approach.