Unable to create MIDlet HelloMidlet
java.lang.ClassNotFoundException: HelloMidlet
at com.sun.midp.midlet.MIDletState.createMIDlet(+29)
at com.sun.midp.midlet.Selector.run(+22)
网上找到代码如下: 编译没有问题,,但是在虚拟机器上一运行,就报上面的错。怎么回事呢?
/*
* HelloMidlet.java
*
* Created on 2007年1月26日, 下午12:34
*/
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
*
* @author zhhz
*/
public class HelloMidlet extends MIDlet implements CommandListener {
/** Creates a new instance of HelloMidlet */
public HelloMidlet() {
}
private Form helloForm;
private StringItem helloStringItem;
private Command exitCommand;
private Form form1;
private Command exitCommand1;
private ChoiceGroup choiceGroup1;
private TextField textField1;
private TextField textField2;
private Command okCommand1;
private Command cancelCommand1;
private Command cancelCommand2;
private Command okCommand2;
private Command okCommand3;
/** This method initializes UI of the application.
*/
private void initialize() {
// Insert pre-init code here
getDisplay().setCurrent(get_helloForm());
// Insert post-init code here
}
/** Called by the system to indicate that a command has been invoked on a particular displayable.
* @param command the Command that ws invoked
* @param displayable the Displayable on which the command was invoked
*/
public void commandAction(Command command, Displayable displayable) {
// Insert global pre-action code here
if (displayable == helloForm) {
if (command == exitCommand) {
// Insert pre-action code here
getDisplay().setCurrent(get_form1());
// Insert post-action code here
}
} else if (displayable == form1) {
if (command == exitCommand1) {
// Insert pre-action code here
exitMIDlet();
// Insert post-action code here
} else if (command == okCommand3) {
// = "/u8BF7/u8F93/u5165/u59D3/u540D/uFF1A"; // Insert pre-action code here
// Do nothing
// Insert post-action code here
}
}
// Insert global post-action code here
}
/**
* This method should return an instance of the display.
*/
public Display getDisplay() {
return Display.getDisplay(this);
}
/**
* This method should exit the midlet.
*/
public void exitMIDlet() {
getDisplay().setCurrent(null);
destroyApp(true);
notifyDestroyed();
}
/** This method returns instance for helloForm component and should be called instead of accessing helloForm field directly.
* @return Instance for helloForm component
*/
public Form get_helloForm() {
if (helloForm == null) {
// Insert pre-init code here
helloForm = new Form(null, new Item[] {
get_helloStringItem(),
get_choiceGroup1()
});
helloForm.addCommand(get_exitCommand());
helloForm.setCommandListener(this);
// Insert post-init code here
}
return helloForm;
}
/** This method returns instance for helloStringItem component and should be called instead of accessing helloStringItem field directly.
* @return Instance for helloStringItem component
*/
public StringItem get_helloStringItem() {
if (helloStringItem == null) {
// Insert pre-init code here
helloStringItem = new StringItem("Hello", "Hello, World!");
// Insert post-init code here
}
return helloStringItem;
}
/** This method returns instance for exitCommand component and should be called instead of accessing exitCommand field directly.
* @return Instance for exitCommand component
*/
public Command get_exitCommand() {
if (exitCommand == null) {
// Insert pre-init code here
exitCommand = new Command("NEXT", Command.EXIT, 1);
// Insert post-init code here
}
return exitCommand;
}
/** This method returns instance for form1 component and should be called instead of accessing form1 field directly.
* @return Instance for form1 component
*/
public Form get_form1() {
if (form1 == null) {
// Insert pre-init code here
form1 = new Form(null, new Item[] {
get_textField1(),
get_textField2()
});
form1.addCommand(get_exitCommand1());
form1.addCommand(get_okCommand3());
form1.setCommandListener(this);
// Insert post-init code here
}
return form1;
}
/** This method returns instance for exitCommand1 component and should be called instead of accessing exitCommand1 field directly.
* @return Instance for exitCommand1 component
*/
public Command get_exitCommand1() {
if (exitCommand1 == null) {
// Insert pre-init code here
exitCommand1 = new Command("exit", Command.EXIT, 1);
// Insert post-init code here
}
return exitCommand1;
}
/** This method returns instance for choiceGroup1 component and should be called instead of accessing choiceGroup1 field directly.
* @return Instance for choiceGroup1 component
*/
public ChoiceGroup get_choiceGroup1() {
if (choiceGroup1 == null) {
// Insert pre-init code here
choiceGroup1 = new ChoiceGroup("asdfasdfkasd;k f/ndsfasd/nf/nas/ndf/na/n/n", Choice.MULTIPLE, new String[0], new Image[0]);
choiceGroup1.setSelectedFlags(new boolean[0]);
// Insert post-init code here
}
return choiceGroup1;
}
/** This method returns instance for textField1 component and should be called instead of accessing textField1 field directly.
* @return Instance for textField1 component
*/
public TextField get_textField1() {
if (textField1 == null) {
// Insert pre-init code here
textField1 = new TextField("/u8BF7/u8F93/u5165/u59D3/u540D/uFF1A", "", 120, TextField.ANY);
// Insert post-init code here
}
return textField1;
}
/** This method returns instance for textField2 component and should be called instead of accessing textField2 field directly.
* @return Instance for textField2 component
*/
public TextField get_textField2() {
if (textField2 == null) {
// Insert pre-init code here
textField2 = new TextField("/u8BF7/u8F93/u5165/u5BC6/u7801/uFF1A", null, 120, TextField.ANY);
// Insert post-init code here
}
return textField2;
}
/** This method returns instance for okCommand1 component and should be called instead of accessing okCommand1 field directly.
* @return Instance for okCommand1 component
*/
public Command get_okCommand1() {
if (okCommand1 == null) {
// Insert pre-init code here
okCommand1 = new Command("cancle", Command.OK, 1);
// Insert post-init code here
}
return okCommand1;
}
java.lang.ClassNotFoundException: HelloMidlet
at com.sun.midp.midlet.MIDletState.createMIDlet(+29)
at com.sun.midp.midlet.Selector.run(+22)
网上找到代码如下: 编译没有问题,,但是在虚拟机器上一运行,就报上面的错。怎么回事呢?
/*
* HelloMidlet.java
*
* Created on 2007年1月26日, 下午12:34
*/
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
*
* @author zhhz
*/
public class HelloMidlet extends MIDlet implements CommandListener {
/** Creates a new instance of HelloMidlet */
public HelloMidlet() {
}
private Form helloForm;
private StringItem helloStringItem;
private Command exitCommand;
private Form form1;
private Command exitCommand1;
private ChoiceGroup choiceGroup1;
private TextField textField1;
private TextField textField2;
private Command okCommand1;
private Command cancelCommand1;
private Command cancelCommand2;
private Command okCommand2;
private Command okCommand3;
/** This method initializes UI of the application.
*/
private void initialize() {
// Insert pre-init code here
getDisplay().setCurrent(get_helloForm());
// Insert post-init code here
}
/** Called by the system to indicate that a command has been invoked on a particular displayable.
* @param command the Command that ws invoked
* @param displayable the Displayable on which the command was invoked
*/
public void commandAction(Command command, Displayable displayable) {
// Insert global pre-action code here
if (displayable == helloForm) {
if (command == exitCommand) {
// Insert pre-action code here
getDisplay().setCurrent(get_form1());
// Insert post-action code here
}
} else if (displayable == form1) {
if (command == exitCommand1) {
// Insert pre-action code here
exitMIDlet();
// Insert post-action code here
} else if (command == okCommand3) {
// = "/u8BF7/u8F93/u5165/u59D3/u540D/uFF1A"; // Insert pre-action code here
// Do nothing
// Insert post-action code here
}
}
// Insert global post-action code here
}
/**
* This method should return an instance of the display.
*/
public Display getDisplay() {
return Display.getDisplay(this);
}
/**
* This method should exit the midlet.
*/
public void exitMIDlet() {
getDisplay().setCurrent(null);
destroyApp(true);
notifyDestroyed();
}
/** This method returns instance for helloForm component and should be called instead of accessing helloForm field directly.
* @return Instance for helloForm component
*/
public Form get_helloForm() {
if (helloForm == null) {
// Insert pre-init code here
helloForm = new Form(null, new Item[] {
get_helloStringItem(),
get_choiceGroup1()
});
helloForm.addCommand(get_exitCommand());
helloForm.setCommandListener(this);
// Insert post-init code here
}
return helloForm;
}
/** This method returns instance for helloStringItem component and should be called instead of accessing helloStringItem field directly.
* @return Instance for helloStringItem component
*/
public StringItem get_helloStringItem() {
if (helloStringItem == null) {
// Insert pre-init code here
helloStringItem = new StringItem("Hello", "Hello, World!");
// Insert post-init code here
}
return helloStringItem;
}
/** This method returns instance for exitCommand component and should be called instead of accessing exitCommand field directly.
* @return Instance for exitCommand component
*/
public Command get_exitCommand() {
if (exitCommand == null) {
// Insert pre-init code here
exitCommand = new Command("NEXT", Command.EXIT, 1);
// Insert post-init code here
}
return exitCommand;
}
/** This method returns instance for form1 component and should be called instead of accessing form1 field directly.
* @return Instance for form1 component
*/
public Form get_form1() {
if (form1 == null) {
// Insert pre-init code here
form1 = new Form(null, new Item[] {
get_textField1(),
get_textField2()
});
form1.addCommand(get_exitCommand1());
form1.addCommand(get_okCommand3());
form1.setCommandListener(this);
// Insert post-init code here
}
return form1;
}
/** This method returns instance for exitCommand1 component and should be called instead of accessing exitCommand1 field directly.
* @return Instance for exitCommand1 component
*/
public Command get_exitCommand1() {
if (exitCommand1 == null) {
// Insert pre-init code here
exitCommand1 = new Command("exit", Command.EXIT, 1);
// Insert post-init code here
}
return exitCommand1;
}
/** This method returns instance for choiceGroup1 component and should be called instead of accessing choiceGroup1 field directly.
* @return Instance for choiceGroup1 component
*/
public ChoiceGroup get_choiceGroup1() {
if (choiceGroup1 == null) {
// Insert pre-init code here
choiceGroup1 = new ChoiceGroup("asdfasdfkasd;k f/ndsfasd/nf/nas/ndf/na/n/n", Choice.MULTIPLE, new String[0], new Image[0]);
choiceGroup1.setSelectedFlags(new boolean[0]);
// Insert post-init code here
}
return choiceGroup1;
}
/** This method returns instance for textField1 component and should be called instead of accessing textField1 field directly.
* @return Instance for textField1 component
*/
public TextField get_textField1() {
if (textField1 == null) {
// Insert pre-init code here
textField1 = new TextField("/u8BF7/u8F93/u5165/u59D3/u540D/uFF1A", "", 120, TextField.ANY);
// Insert post-init code here
}
return textField1;
}
/** This method returns instance for textField2 component and should be called instead of accessing textField2 field directly.
* @return Instance for textField2 component
*/
public TextField get_textField2() {
if (textField2 == null) {
// Insert pre-init code here
textField2 = new TextField("/u8BF7/u8F93/u5165/u5BC6/u7801/uFF1A", null, 120, TextField.ANY);
// Insert post-init code here
}
return textField2;
}
/** This method returns instance for okCommand1 component and should be called instead of accessing okCommand1 field directly.
* @return Instance for okCommand1 component
*/
public Command get_okCommand1() {
if (okCommand1 == null) {
// Insert pre-init code here
okCommand1 = new Command("cancle", Command.OK, 1);
// Insert post-init code here
}
return okCommand1;
}