Motoroal Razor V3, J2ME-Programm geht nur im Emulator
-
Hallo,
ich habe ein Probleme. Das J2ME-Programm geht perfekt im Emulator Toolkit Version 2.2, aber im Handy wird keine Antwort generiert. Das Handy spuckt auch keinen Fehler. NIX. Und am Webserver kommen keine Daten an.
import javax.microedition.lcdui.*; import javax.microedition.midlet.*; import javax.microedition.io.*; import java.io.*; public class EmailMIDlet extends MIDlet implements CommandListener { Display display = null; TextField ServerFeld = null; TextField BefehlFeld = null; Form form; static final Command sendCommand = new Command("senden", Command.OK, 2); static final Command clearCommand = new Command("zurück", Command.STOP, 3); String Servername; String Befehl; public EmailMIDlet() //Konstruktor { display = Display.getDisplay(this); form = new Form("Befehl absetzen"); ServerFeld = new TextField("Servername:", "", 15, TextField.EMAILADDR); BefehlFeld = new TextField("Befehl: ", "", 15, TextField.ANY); } public void startApp() throws MIDletStateChangeException { form.append(ServerFeld); form.append(BefehlFeld); form.addCommand(clearCommand); form.addCommand(sendCommand); form.setCommandListener(this); display.setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean unconditional) { notifyDestroyed(); } public void commandAction(Command c, Displayable d) { String label = c.getLabel(); if(label.equals("zurück")) { destroyApp(true); } else if (label.equals("senden")) { Servername = ServerFeld.getString(); Befehl = BefehlFeld.getString(); EmailClient client = new EmailClient(this, Servername, Befehl); client.start(); } } }
import javax.microedition.midlet.*; import javax.microedition.io.*; import javax.microedition.lcdui.*; import java.io.*; import java.util.*; public class EmailClient implements Runnable { private EmailMIDlet parent; private Display display; private Form f; private StringItem si; private SocketConnection sc; private InputStream is; private OutputStream os; HttpConnection connection = null; private String Servername, Befehl; private String url = "geheime URL"; //URL zum Serverskript public EmailClient (EmailMIDlet m, String Servername, String Befehl) //Konstruktor mit Attributen { parent = m; this.Servername = Servername; this.Befehl = Befehl; url = url + Servername + "&befehl=" + Befehl; display = Display.getDisplay(parent); f = new Form("Email Client"); si = new StringItem("Antwort: " , " "); f.append(si); display.setCurrent(f); } public void start() //Starten des Threads { Thread thr = new Thread(this); thr.start(); } public void run() //Thread { try { connection = (HttpConnection)Connector.open(url); connection.setRequestMethod(HttpConnection.GET); connection.setRequestProperty("IF-Modified-Since","20 Jan 2001 16:19:14 GMT"); connection.setRequestProperty("User-Agent","Profile/MIDP-2.0 Confirguration/CLDC-1.0"); connection.setRequestProperty("Content-Language", "en-CA"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); os = connection.openOutputStream(); is = connection.openDataInputStream(); StringBuffer sb = new StringBuffer(); int c = 0; while (((c = is.read()) != -1) ) { sb.append((char) c); } si.setText(" " + sb.toString()); } catch(IOException e) { Alert alarm = new Alert("HTTP-Server", "Verbindung zum HTTP-Server fehlgeschlagen", null, AlertType.ERROR); alarm.setTimeout(Alert.FOREVER); display.setCurrent(alarm); } finally { try { if(is != null) { is.close(); } if(os != null) { os.close(); } if(sc != null) { sc.close(); } } catch(IOException e) { e.printStackTrace(); } } } public void commandAction(Command c, Displayable s) { if (c == Alert.DISMISS_COMMAND) { parent.notifyDestroyed(); parent.destroyApp(true); } } }