PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Java-Problem mit J2ME


OssiMitHerz
2006-01-13, 13:32:09
hallo

ich habe ein Problem mit der J2ME Wireless Toolkit Version 2.2

Ich bekomme immer folgende Fehlermeldung:

java.lang.SecurityException: Application not authorized to access the restricted API
at com.sun.midp.security.SecurityToken.checkIfPermissionAllowed(+40)
at com.sun.midp.security.SecurityToken.checkIfPermissionAllowed(+7)
at com.sun.midp.midletsuite.MIDletSuiteImpl.checkIfPermissionAllowed(+8)
at com.sun.midp.midlet.MIDletState.<init>(+78)
at javax.microedition.midlet.MIDletProxy.<init>(+5)
at javax.microedition.midlet.MIDlet.<init>(+13)
at SimpleGETExample.<init>(+4)
at Hello.commandAction(+74)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)

ich habe zwei klassen, die Hauptklasse erzeugt zwei eingabefelder und erstellt eine eine Instanz von einer anderen Klasse, die als Übergabeparameter eine URL (wird aus den beiden Feldern erzeugt) bekommt.

Bei der alten Toolkit Version 1.0 funktioniert alles

Auf dem Handy (Razor V3) wird die Fehlermeldung "Application Error" angezeigt

Vielleicht hat irgendwer eine Idee
Danke im Voraus

HellHorse
2006-01-13, 14:54:31
Vielleicht hat irgendwer eine Idee
Fehlermeldung überhaupt gelesen?
Application not authorized to access the restricted API
=> Sandbox, Aktion nicht erlaubt

OssiMitHerz
2006-01-14, 16:33:48
ja aber es funktioniert mit der Toolkit Version 1.0

Woran liegt das? Das ist doch unlogisch, oder? :confused:

ich bin nebenbei bemerkt Anfänger im Bereich Java

HellHorse
2006-01-14, 18:18:59
Was machen denn der SimpleGETExample Konstruktor und Hello#commandAction? Schau dir mal den Kommentar vom MIDlet Konstruktor an, was dort bezgl. Sichterheit steht.

OssiMitHerz
2006-01-14, 19:22:43
Ok, das probiere ich mal

Danke

OssiMitHerz
2006-01-14, 19:31:45
Ok, das probiere ich mal

Danke

so hier nochmal die Quelltexte der beiden Dateien ( ich weiss, es sieht wüst aus )

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.io.*;
import javax.microedition.io.*;

public class Hello extends MIDlet implements CommandListener {
Form mForm;
TextField mTextField;
TextField mTextField2;
String ServerName;
String Befehl;
String url = "geheime URL";

public Hello() {
mForm = new Form("Hello");
mTextField = new TextField("Servername:", "", 12, TextField.ANY);
mForm.append(mTextField);
mTextField2 = new TextField("Befehl: ", "", 12, TextField.ANY);
mForm.append(mTextField2);
Command okCommand = new Command("OK", Command.OK, 1);
mForm.addCommand(okCommand);
mForm.setCommandListener(this);
}

public void commandAction(Command c, Displayable d) {
ServerName = mTextField.getString();
Befehl = mTextField2.getString();
url = url + ServerName + "&befehl=" + Befehl;
SimpleGETExample hc = new SimpleGETExample(this, url);
}

public void startApp() {
Display.getDisplay(this).setCurrent(mForm);
}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {
this.notifyDestroyed();
}

}

import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class SimpleGETExample extends MIDlet{

private Display dsp;
private Hello midlet;

String url = "";

public SimpleGETExample(Hello m,String n) {
midlet = m;
url = n;
dsp = Display.getDisplay(midlet);

}

public void startApp() {
try {
testGET(url);
} catch (IOException e) {
System.out.println("IOException " + e);
e.printStackTrace();
}
}

public void pauseApp() { }
public void destroyApp(boolean unconditional) { }

void testGET(String url) throws IOException {
HttpConnection connection = null;
InputStream is = null;
OutputStream os = null;
StringBuffer stringBuffer = new StringBuffer();
TextBox textBox = null;

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();
int ch;
while ((ch = is.read()) != -1) {
stringBuffer.append((char) ch);
}
textBox = new TextBox("Simple GET Test", stringBuffer.toString(), 1024, 0);

} finally {
if(is!= null) {
is.close();
}
if(os != null) {
os.close();
}
if(connection != null) {
connection.close();
}
}
dsp.setCurrent(textBox);
}
}

SimpleGETEyample schickt die Daten zu einem PHP-Skript, das Daten auswertet und eine Meldung zurückschickt

HellHorse
2006-01-15, 17:40:04
Es gibt [ code ] - Tags, bitte benütze sie.

Aus meiner Sicht geschieht der Fehler hier:

public SimpleGETExample(Hello m,String n) {
midlet = m;
url = n;
dsp = Display.getDisplay(midlet);

}

und zwar glaube ich, dass der Aufruf des Superkonstruktors fehlschlägt. Debug es mal, und schau dir mal im Detail die Doku von MIDlet an was dort bzgl. Sicherheit/Sandbox steht.


SimpleGETEyample schickt die Daten zu einem PHP-Skript, das Daten auswertet und eine Meldung zurückschickt
Prüf mal, ob so was im allgemeinen erlaubt ist.

OssiMitHerz
2006-01-18, 12:25:43
Nein das Problem liegt ganz woanders.

Man darf aus einem MIDlet kein anderes MIDlet aufrufen, nur zur Info.

Steht so auf der sun-seite

trotzdem danke