Current position:  Home > Default > Error in running MIDlet

Error in running MIDlet

Time:October 11
Advertisement
Hi, all
I have a problem around MIDlet.
Here, the MIDlet source code :
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.io.*;
public class BolaMidlet extends Form implements CommandListener
+{     +
private Display display;
private static final Command cmExit = new Command("Keluar", Command.EXIT, 1);
private static final Command cmSubmit = new Command("Login", Command.OK, 1);
private BolaMidlet midlet;
private TextField tfUsername;
private TextField tfMajor;
private String result;
public BolaMidlet(BolaMidlet midlet, Display display)
+{+
super("BolaMidlet");
this.midlet = midlet;
this.display = display;
tfUsername = new TextField("Username", "", 20, TextField.ANY);
tfMajor = new TextField("Major", "", 20, TextField.ANY);
append(tfUsername);
append(tfMajor);
addCommand(cmExit);
addCommand(cmSubmit);
setCommandListener(this);
+}+
public void startApp()
+{+
display.setCurrent(this);
+}+
public void pauseApp()
+{+
display.setCurrent(null);
+}+
public void destroyApp(boolean unconditional)
+{+
+}+
public void exitMIDlet()
+{+
destroyApp(false);          
+}     +
public void commandAction(Command c, Displayable s)
+{+
if(c == cmExit)
+{+
midlet.exitMIDlet();
+}+
else if(c == cmSubmit)
+{+
try
+{+
submit(tfUsername.getString(), tfMajor.getString());
+}catch(Exception e)+
+{+
e.printStackTrace();
+}+
+}          +
+}+
public void submit(String user, String major)
throws IOException
+{+
String url = "http://localhost:8080/hello/sayhello?user=user&pass=major";
HttpConnection hc = null;
StringBuffer sb = null;
InputStream is = null;
try
+{+
hc = (HttpConnection)Connector.open(url, Connector.READ_WRITE);
hc.setRequestMethod(HttpConnection.GET);
hc.setRequestProperty("User-Agent", "Profile/MIDP-2.1 Configuration/CLDC-1.1");
hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
if(hc.getResponseCode() == HttpConnection.HTTP_OK)
+{+
sb = new StringBuffer();
int ch;
is = hc.openInputStream();
while((ch = is.read()) != -1)
sb.append((char)ch);
+}+
else
+{+
System.out.println("Network error");
+}     +
+}catch(IOException e)+
+{+
e.printStackTrace();
if(hc != null)
hc.close();
if(sb != null)
result = sb.toString();
if(is != null)
is.close();
+}finally+
+{+
if(is != null)                    
is.close();                    
if(sb != null)               
result = sb.toString();                    
if(hc != null)                    
hc.close();                    
+}+
+}+
when I compiled it, there was no problem.
But, when I launched it on the emulator
there was an error in WTK console like this :
Unable to create MIDlet BolaMidlet
java.lang.IllegalAccessException
at com.sun.midp.midlet.MIDletState.createMIDlet(34)+
at com.sun.midp.midlet.Selector.run(22)+
and then the emulator said : BolaMidlet, BolaMidlet exception : java.lang.IllegalAccessException
can someone help me to solve this ?
I really need help for this one.
Thank You,
Best Regards,
CHi
Edited by: ichiwan on Sep 30, 2007 11:23 AM
Advertisement
{color:#000080}The code you have posted is for a class that extends Form, not MIDlet.
To post code, use code tags --{color} [code]CODE[/code] {color:#000080}is displayed as CODEPlease do not try to format parts of your code as bold or italic as that reduces the readability still more.
db{color}