07-20-2012 05:43 AM
I'm making an application that can receive sms with the code below:
package mypackage;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.MessageListener;
import javax.wireless.messaging.TextMessage;
import net.rim.device.api.system.ApplicationManager;
import net.rim.device.api.system.ApplicationManagerExcept
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.container.MainScreen;
/**
* A class extending the MainScreen class, which provides default standard
* behavior for BlackBerry GUI applications.
*/
public final class MyScreen extends MainScreen implements MessageListener
{
MessageConnection sambung ;
EditField isi ;
/**
* Creates a new MyScreen object
*/
public MyScreen( )
{
// Set the displayed title of the screen
setTitle("MyTitle");
isi = new EditField("","");
add(isi);
try {
this.sambung = (MessageConnection)Connector.open("sms://");
this.sambung.setMessageListener(this);
}
catch (Exception e)
{
System.out.println("Exception: " + e);
}
}
public void notifyIncomingMessage(final MessageConnection sambung) {
new Thread ()
{
MessageConnection conn;
Thread set (MessageConnection conn){
this.conn =conn ;
return this;
}
public void run (){
try {
TextMessage pesan = (TextMessage)conn.receive();
String perintah = pesan.getPayloadText();
isi.setText(perintah);
}catch (IOException e) {
System.out.println("ExceptionMessage :"+e);
} catch (ApplicationManagerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.set(sambung).start();
}
}
But when I try the application on the device is actually on editfield can not display a currently received sms. Can someone can give me a correction to the source code .
07-20-2012 06:11 AM
I presume you are seeing an IllegalStateException, on this line:
isi.setText(perintah);
in which case replace this line with something like:
UiAPplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
isi.setText(perintah);
}
});
You might have to create sdome "final" references to get this to compile.
If this is not the problem you are seeing, can you please describe what happens exactly?
07-21-2012 02:02 PM
Thanks for your respond sir , my application consists of a editfieldand if an incoming sms content will appear in the editfield and I've tried your suggestion but no effect
07-21-2012 02:42 PM
So when debugging and stepping through the code, what exactly happens?