CCMOVE 移动天使手机论坛 ->地方论坛->Unable to create MIDlet
共0条/0页
  主题:Unable to create MIDlet
一碌蔗
楼主 该贴获得 鲜花0   鸡蛋0 [投鲜花]    购买道具     [投鸡蛋]  
[文字推荐]  
Unable to create MIDlet



以下是全部代码,主要想实现的是一个表单带四个文本框分别输入 姓名,移动电话号码,固定

电话号码和Email 地址,运行的环境j2sdk1.4.2_09,编译工具wireless toolkit 2.5

以下的代码可以全部通过编译,但是出现下面的错误提示,请高手指点,错误出现在哪里,谢谢

!我想了很久都想不出来,也到过国内的许多论坛都找不好的解决方法!
Unable to create MIDlet NewRecordForm
java.lang.ClassNotFoundException: NewRecordForm
at com.sun.midp.midlet.MIDletState.createMIDlet(+29)
at com.sun.midp.midlet.Selector.run(+22)

======================================================
package PhoneBook;

public class BookConstant {
public static final String alertTitle = "信息提示";

public static final String listTitle = "主菜单";

public static final String[] menu = { "添加记录", "查找记录", "清空电话本", "浏览电话本",
"系统帮助" };

public static final String author = "作者";

public static final String add_record = "添加记录";

public static final String delete_phonebook = "删除电话本?";

public static final String name = "姓名";

public static final String mobile = "移动电话";

public static final String phone = "固定电话";

public static final String email = "电子信箱";

public static final String choice = " 选项";

public static final String detail = "详细信息";

public static final String listPhoneTitle = "电话本列表";

public static final String search = "查询电话";

public static final String userNameNull = "用户名不能为空";

public static final String mobilePhoneNull = "电话号码不能为空";

public static final String deleteing = "正在删除纪录...";

public static final String gettingList = "正在浏览纪录...";

public static final String record_added = "添加记录完成";

public static final String record_exist = "记录已经存在";

public static final String DELETE_RECORD = "删除";

public static final String DETAIL_INFO = "详细信息";

public static final String rsName = "phonebook";

public static final String rs_index = "index";

}
======================================

/*
* 基本的记录字段分割和转换字节数组
*/

package PhoneBook;

import java.io.*;

public class BookAccount {
private String userName = "";

private String mobilePhone = "";

private String email = "";

private String phone = "";

public BookAccount(String userName, String mobilePhone, String email,
String phone) {
this.userName = userName;
this.mobilePhone = mobilePhone;
this.email = email;
this.phone = phone;
}

public BookAccount() {

}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getMobilePhone() {
return mobilePhone;
}

public void setMobilePhone(String mobilePhone) {
this.mobilePhone = mobilePhone;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public byte[] serialize() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);

dos.writeUTF(userName);
dos.writeUTF(mobilePhone);
dos.writeUTF(email);
dos.writeUTF(phone);

baos.close();
dos.close();

return baos.toByteArray();
}

public static BookAccount deserialize(byte[] data) throws IOException {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bais);
BookAccount account = new BookAccount();
account.userName = dis.readUTF();
account.mobilePhone = dis.readUTF();
account.email = dis.readUTF();
account.phone = dis.readUTF();

bais.close();
dis.close();

return account;
}

public static boolean matches(byte[] data, String userName)
throws IOException {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bais);
try {
return (dis.readUTF()).equals(userName);
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
}
======================================
/*
* 查找名字是否存在
*/

package PhoneBook;

import javax.microedition.rms.*;

public class FindFilter implements RecordFilter {
private String filterName = null;

public FindFilter(String name) {
this.filterName = name;
}

public boolean matches(byte[] rec) {
BookAccount account = null;
String name = null;
try {
account = BookAccount.deserialize(rec);
name = account.getUserName();
account = null;

} catch (Exception e) {
account = null;
System.out.println("deserialize error");
}
//按name搜索
if (name != null) {
if (filterName.equals(name)) {
return true;
}
}
return false;

}

}
======================================
/*
* 添加新记录
*/

package PhoneBook;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.rms.*;


public class NewRecordForm extends Form implements CommandListener{

private TextField nameField;
    private TextField mobileField;
    private TextField phoneField;
    private TextField emailField;
    private Displayable dis;
    private MIDlet mid;
    private RecordStore rs = null;
   
    private static final Command saveCommand = new Command("保存", Command.OK, 2);
    private static final Command backCommand = new Command("返回", Command.BACK, 3);
public NewRecordForm(String title,Displayable dis,MIDlet mid,RecordStore rs) {
super(title);
this.dis = dis;
this.mid = mid;
this.rs = rs;

nameField = new TextField(BookConstant.name, null, 25, TextField.ANY);
        mobileField = new TextField(BookConstant.mobile, null, 25,
                TextField.PHONENUMBER);      
        phoneField = new TextField(BookConstant.phone, null, 25, TextField.PHONENUMBER);
        emailField = new TextField(BookConstant.email, null, 25, TextField.EMAILADDR);
       
        this.append(nameField);
        this.append(mobileField);
        this.append(phoneField);
        this.append(emailField);          
       
      
        this.addCommand(saveCommand);
        this.addCommand(backCommand);
        this.setCommandListener(this);    
       
       

}

public void commandAction(Command c, Displayable d){
if(c==saveCommand){
if(rs != null){
if(nameField.getString().length() == 0){

Alert a_name = new Alert("提醒", "姓名不能为空,请

输入姓名",
                                null, AlertType.ERROR);
a_name.setTimeout(Alert.FOREVER);
Display.getDisplay(mid).setCurrent(a_name);
return;
}

//查找是否已经存在相同的名字
RecordFilter rf = new FindFilter(nameField.getString());
        RecordEnumeration re = null;
        try {
          re = rs.enumerateRecords(rf, null, false);
         // if (re.hasNextElement()) {
         //   re.nextRecord();
         // }
        }
        catch (Exception e) {
        }
//如果已经存在一个相同的名字则返回
        if(re.numRecords()>0){
        Alert a_same = new Alert("提醒", "你输入的姓名已经存在,请

输入其他名字",
                                null, AlertType.ERROR);
        a_same.setTimeout(Alert.FOREVER);
Display.getDisplay(mid).setCurrent(a_same);
re.destroy();
        return;
        }
//添加一个新记录
BookAccount account = new BookAccount(nameField.getString

(),
mobileField.getString

(),emailField.getString(),
phoneField.getString());
try{
byte[] rec = account.serialize();


rs.addRecord(rec, 0, rec.length);
Display.getDisplay(mid).setCurrent(dis);
}catch(Exception e){

}
}

}else if(c == backCommand){
Display.getDisplay(mid).setCurrent(dis);

}

    }

}


最珍贵的东西是免费的    法拉利腕表亮相伦敦车展
    
给我留言
   发贴时间:2008-6-19 21:59:47
引用 编辑
共0条/0页
表情:
内容: 

奥运很好很和谐,禁止拿奥运开玩笑,禁止发布未经证实的消息
Ctrl+Enter 快速提交