×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    26

    java.lang.ClassCastException error in Eclipse

    eclipse3.3.1+eclipseme1.7.6+wtk2.5.2 +sdk1.6.0

    error is:
    java.lang.ClassCastException
    at Login.commandAction(+1)
    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.handleVmEvent(+186)
    at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)

    "Errors during build.
    ***Errors running builder 'Preverification' on project 'Login'.*
    Illegal Manifest Entry Key or Value "de.schlichtherle.io.ArchiveFileSystem$ArchiveReadOnlyException: Archive file is read-only!"
    de.schlichtherle.io.ArchiveFileSystem$ArchiveReadOnlyException: Archive file is read-only! ".

    problem occurred
    building workspace error running builder "preverification" on project 'Login'.*

    Source not found
    The JAR of the classfile belongs to the container 'J2ME library [sun java wirless toolkit 2.5.1 for cldc/defaultcolorphone ]' which does not allow modifications to source attachments on its entries.

    and below error while integrate the wtk2.5.1

    set platform failed reason no message java.lang.reflect.invocationtargetexception

    problem occurred
    launching new_configuration errors during build error running builder"preverification"

    i can't login, both okCommand and exitCommand are out of work, and i can't display icons and images, or no display on the emulator.
    i really can't solve these problems in eclipse, please help!
    waiting on line.
    thanks.
    Last edited by jacky521; 2007-10-11 at 05:49.
    Just Do it !

  2. #2
    Registered User
    Join Date
    Jul 2007
    Posts
    26

    Re: java.lang.ClassCastException error in Eclipse

    source code is:
    import java.io.IOException;

    import javax.microedition.lcdui.Alert;
    import javax.microedition.lcdui.AlertType;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.Image;
    import javax.microedition.lcdui.ImageItem;
    import javax.microedition.lcdui.List;
    import javax.microedition.lcdui.TextField;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;

    public class Login extends MIDlet implements CommandListener
    {
    private Display display;
    private static String menuItems[]={
    "移动监控","移动查询","移动报警","系统设置" };
    private List mainMenu=new List("欢迎使用移动监控系统", List.IMPLICIT,menuItems,null);
    //二级菜单
    private static String monitorItems[]={"图像监控","区域组监控"};
    private List monitor =new List("移动监控",List.IMPLICIT,monitorItems,null);
    private static String queryItems[]={"信息点属性","信息点实时值","信息点历史值"};
    private List query = new List("移动查询",List.IMPLICIT,queryItems,null);
    private static String warningItems[]={"信息点历史报警查询","信息点实时报警查询"};
    private List warning=new List("移动报警",List.IMPLICIT,warningItems,null);
    private static String settingItems[]={"账号密码管理","信息点组设置"};
    private List setting=new List("系统设置",List.IMPLICIT,settingItems,null);

    //三级菜单
    private static String imageControlItems[]={"实时图像获取","历史图像检查"};
    private List image =new List("图像监控",List.IMPLICIT,imageControlItems,null);
    private static String groupControlItems[]={"区域信息点监控","实时详情监控"};
    private List group =new List("区域组监控",List.IMPLICIT,groupControlItems,null);

    private static String propertyItems[]={"信息点名称","信息点描述"};
    private List property =new List("信息点属性",List.IMPLICIT,propertyItems,null);
    private static String realtimeItems[]={"按信息点组","按信息点名称","按信息点描述"};
    private List realtime =new List("信息点实时值",List.IMPLICIT,realtimeItems,null);
    private static String recordItems[]={"按历史信息点组","按历史信息点名称","按历史信息点描述"};
    private List record =new List("信息点历史值",List.IMPLICIT,recordItems,null);

    private static String recordqueryItems[]={"按报警组","按报警信息点名称","按报警信息点描述"};
    private List recordquery =new List("信息点历史报警查询",List.IMPLICIT,recordqueryItems,null);
    private static String realtimequeryItems[]={"上上限","上限","下限","下下限"};
    private List realtimequery =new List("信息点实时报警查询",List.IMPLICIT,realtimequeryItems,null);

    private static String manageItems[]={"按报警组","按报警信息点名称","按报警信息点描述"};
    private List manage =new List("账号密码管理",List.IMPLICIT,manageItems,null);
    private static String infogroupItems[]={ "报警分组设置","查询分组设置","监控分组设置"};
    private List infogroup =new List("信息点组设置",List.IMPLICIT,infogroupItems,null);

    private Form form;
    // private Form Monitorform;
    // private Form menuform;
    private TextField userName;
    private TextField password;
    private ImageItem imageItem;
    private Image aImage;

    //private List menu = null; // main menu
    //private List Choice = null; // list of choices

    static final Command exitCommand =new Command("退出",Command.EXIT,1);
    static final Command okCommand =new Command("确定",Command.OK,2);
    static final Command backCommand = new Command("返回", Command.BACK, 3);
    private String currentMenu = null;

    public Login()
    {
    userName=new TextField("用户名 :","",15,TextField.ANY);
    password=new TextField("密 码 :","",15,TextField.PASSWORD);

    try{
    aImage=Image.createImage("/nokia.png");
    }
    catch(Exception e){ };
    imageItem=new ImageItem("\n 请输入用户名和密码: ",aImage,ImageItem.LAYOUT_CENTER,"#?@");

    }
    public void startApp() throws MIDletStateChangeException
    {
    display=Display.getDisplay(this);
    form=new Form(" 您尚未登录 ...");
    form.append(imageItem);
    form.append(userName);
    form.append(password);
    form.addCommand(exitCommand);
    form.addCommand(okCommand);
    currentMenu="logging";
    form.setCommandListener(this);
    display.setCurrent(form);

    monitor.addCommand(backCommand);
    monitor.addCommand(okCommand);
    monitor.setCommandListener(this);
    query.addCommand(okCommand);
    query.addCommand(backCommand);
    query.setCommandListener(this);
    warning.addCommand(backCommand);
    warning.setCommandListener(this);
    setting.addCommand(backCommand);
    setting.setCommandListener(this);
    image.addCommand(backCommand);
    image.setCommandListener(this);
    group.addCommand(backCommand);
    group.setCommandListener(this);
    property.addCommand(backCommand);
    property.setCommandListener(this);
    realtime.addCommand(backCommand);
    realtime.setCommandListener(this);
    record.addCommand(backCommand);
    record.setCommandListener(this);
    recordquery.addCommand(backCommand);
    recordquery.setCommandListener(this);
    realtimequery.addCommand(backCommand);
    realtimequery.setCommandListener(this);
    manage.addCommand(backCommand);
    manage.setCommandListener(this);
    infogroup.addCommand(backCommand);
    infogroup.setCommandListener(this);

    }
    public void destroyApp(boolean arg0) throws MIDletStateChangeException {
    notifyDestroyed();
    }
    public void pauseApp()
    {
    }
    public void main() {
    //display.setCurrent(mainMenu);
    //currentMenu = "Main";
    }

    public void validateUser(String name, String password) {
    if (name.equals("jacky") && password.equals("")) {
    menu();
    } else {
    tryAgain();
    }
    }
    public void menu() {
    mainMenu=new List("欢迎使用移动监控系统", List.IMPLICIT,menuItems,null);
    mainMenu.addCommand(backCommand);
    mainMenu.addCommand(okCommand);
    mainMenu.setCommandListener(this);
    display.setCurrent(this.mainMenu);
    }
    public void tryAgain() {
    try{
    aImage=Image.createImage("/soup.gif");
    }
    catch(Exception e){ }
    Alert error = new Alert("登录失败", "用户名或密码错误,请再试一次", aImage, AlertType.ERROR);
    error.setTimeout(Alert.FOREVER);
    userName.setString("");
    password.setString("");
    display.setCurrent(error, form);
    }
    private Image createImage(String name){
    Image cImage = null;
    try{
    cImage = Image.createImage(name);
    }
    catch(IOException e){
    }
    return cImage;
    }
    public void commandAction(Command c, Displayable s)
    {
    List list =(List) s;
    if(c==List.SELECT_COMMAND){
    int index=list.getSelectedIndex();
    if(list==this.mainMenu){
    switch(index){
    case 0: display.setCurrent(this.monitor); break;
    case 1: display.setCurrent(this.query); break;
    case 2: display.setCurrent(this.warning); break;
    case 3: display.setCurrent(this.setting);
    } }
    else if (list==this.monitor){
    switch(index){
    case 0: display.setCurrent(this.image); break;
    case 1: display.setCurrent(this.group);
    } }
    else if (list==this.query){
    switch(index){
    case 0: display.setCurrent(this.property);break;
    case 1: display.setCurrent(this.realtime);break;
    case 2: display.setCurrent(this.record);
    } }
    else if(list==this.warning){
    switch(index){
    case 0: display.setCurrent(this.realtimequery);break;
    case 1: display.setCurrent(this.recordquery);
    } }
    else if(list==this.setting){
    switch(index){
    case 0: display.setCurrent(this.manage);break;
    case 1: display.setCurrent(this.infogroup);

    }
    }
    } else if(c==backCommand){
    if (list==this.monitor||list==this.query||list==this.warning||list==this.setting){
    display.setCurrent(this.mainMenu); }
    else if(list==this.image||list==this.group){
    display.setCurrent(this.monitor); }
    else if(list==this.property||list==this.realtime||list==this.record){
    display.setCurrent(this.query); }
    else if(list==this.realtimequery||list==this.recordquery){
    display.setCurrent(this.warning); }
    else if(list==this.manage||list==this.infogroup){
    display.setCurrent(this.setting); }
    }

    else if(c==exitCommand) {
    try{
    destroyApp(false);
    //notifyDestroyed();
    } catch(MIDletStateChangeException e){
    e.printStackTrace();
    }
    }
    else if(c==okCommand) {
    if(currentMenu=="logging"){
    validateUser(userName.getString(), password.getString());
    }
    //else if(list==mainMenu){
    //display.setCurrent(this.monitor);
    //} else if (list==monitor)

    }
    }
    }
    Last edited by jacky521; 2007-10-11 at 03:58.
    Just Do it !

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    You do a type cast to ‘List’ in the first line of ‘commandAction’ method of your ‘Login’ class.

  4. #4
    Registered User
    Join Date
    Jul 2007
    Posts
    26

    Re: java.lang.ClassCastException error in Eclipse

    yes, i've know that, but now my new problem is

    Class File Editor:
    Source not found:
    The Jar of this classfile belongs to the container 'J2ME library [ Sun Java (TM) Wireless Toolkit 2.5.1 for CLDC/DefaultColorPhone]'which does not allow modifications to source attachments on its entries.

    i don't know how to solve it, can anybody help me !
    with many thanks
    Just Do it !

Similar Threads

  1. Please HELP. Impossible Eclipse + Carbide.j
    By videador in forum Mobile Java Tools & SDKs
    Replies: 13
    Last Post: 2007-03-22, 06:06
  2. Eclipse 3.1.2 || Eclipse 3.2
    By rolecram in forum Mobile Java Tools & SDKs
    Replies: 8
    Last Post: 2007-03-12, 23:55
  3. Carbide.j 1.5 Eclipse 3.1 integration problem !
    By osman911 in forum Mobile Java Tools & SDKs
    Replies: 3
    Last Post: 2006-12-15, 10:32
  4. Using Nokia Demo Projects with Eclipse 3.2.0
    By PionsysAtNokia in forum Mobile Java Tools & SDKs
    Replies: 5
    Last Post: 2006-10-10, 15:24
  5. Nokia Connectivity Framework , Eclipse and a BT Dongle
    By shriansh in forum Bluetooth Technology
    Replies: 4
    Last Post: 2006-02-15, 19:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×