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
Developer
KeniF
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

Re: java.lang.Error on Wi-Fi connection

[ Edited ]

yes, an AP has been set up and I can browse normally, but a yellow icon (=) can be seen next to the AP name.

 

Could it be my GTP class which the constructor contains the following ?

 

private SocketConnection sock;

GTP(SocketConnection sock){
this.sock=sock;
}

 

Message Edited by KeniF on 09-16-2008 05:44 PM
Please use plain text.
Developer
richard_puckett
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Re: java.lang.Error on Wi-Fi connection

Yeah, mine's yellow too.  Let's try to establish a baseline.  Compile/sign this complete app and see if it works.

 

import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import javax.microedition.io.Connector; import javax.microedition.io.SocketConnection; import net.rim.device.api.system.WLANInfo; import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.component.RichTextField; import net.rim.device.api.ui.container.MainScreen; public class TestSocket extends UiApplication { private static class TestSocketScreen extends MainScreen { public TestSocketScreen() { if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) { try { SocketConnection sock = (SocketConnection) Connector.open("socket://www.mobiyana.com:80;interface=wifi"); DataInputStream in = sock.openDataInputStream(); DataOutputStream out = sock.openDataOutputStream(); add(new RichTextField("TestSocketScreen: success")); } catch (IOException e) { add(new RichTextField("TestSocketScreen: exception: " + e.toString())); } } else { add(new RichTextField("TestSocketScreen: WLAN not connected")); } } } public static void main(String[] args) { TestSocket app = new TestSocket(); app.enterEventDispatcher(); } TestSocket() { pushScreen(new TestSocketScreen()); } }

 

Please use plain text.
Developer
KeniF
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

Re: java.lang.Error on Wi-Fi connection

[ Edited ]

Success! :smileysurprised:

 

I think I kinda know the reason, my BackgroundThread class which does the connection only extends Thread so it hasn't enterEventDispatcher() ??

 

 

public static void main(String[]args){
// Load the GUI (entry point 1)
if(args!=null&&args.length>0&&args[0].equals("gui")){
smGUI=new SyncMyGUI();
smGUI.enterEventDispatcher();
}// GUI

else{ // Blackberry Autostart (entry point 2)
SMOptionsProvider optionsProvider=new SMOptionsProvider();
OptionsManager.registerOptionsProvider(optionsProvider);
//makes sure only 1 instance is created

bgThread=BackgroundThread.waitForSingleton();
bgThread.start();

}// autostart
}//main

 

 and..

 

final class BackgroundThread extends Thread{

public void run(){
try{
while(true){
/* USING WIFI ******************************************/
if(useWIFI){
syncMyState=State.SYNCMY_START_WIFI;
invokeGUI();
if(wlanAvailable()){
syncMyState=State.GTP_ATMPT_CONNECT;
techInUse=State.USING_WIFI;
try{
invokeGUI();

sock=(SocketConnection)Connector.open("socket://81.86.99.189:47962;interface=wifi");
InputStream in=sock.openInputStream();
OutputStream out=sock.openOutputStream();

Message Edited by KeniF on 09-16-2008 06:32 PM
Please use plain text.
Developer
KeniF
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

Re: java.lang.Error on Wi-Fi connection

found the solution!  Thanks Richard, you did inspire me to find out the problem, and I'll get you a beer if you come to Manchester :smileyvery-happy:

 

class extends UiApplication /*HERE*/ public static void main(String[]args){ // Load the GUI (entry point 1) if(args!=null&&args.length>0&&args[0].equals("gui")){ smGUI=new SyncMyGUI(); smGUI.enterEventDispatcher(); }// GUI else{ // Blackberry Autostart (entry point 2) SMOptionsProvider optionsProvider=new SMOptionsProvider(); OptionsManager.registerOptionsProvider(optionsProvider); //makes sure only 1 instance is created SyncMy sm= new SyncMy(); /*HERE*/ sm.enterEventDispatcher(); /*HERE*/ }// autostart }//main /* NEW CONSTRUCTOR */ SyncMy(){ bgThread=BackgroundThread.waitForSingleton(); bgThread.start(); }

 

 

 

Please use plain text.