2011-09-03 90 views
1

我正在使用JavaMe。屬性錯誤無效

每次我試圖初始化列表對象我收到以下錯誤:

的屬性空的值不是在Mac OSX獅子的正確格式

我使用Eclipse和JRE 6。

這裏是我的簡單的代碼:

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

public class ListTest extends MIDlet implements CommandListener { 

private Display display; 
private List optionsItem; 
private Command exit; 

public ListTest(){ 
    optionsItem = new List("List types of Item", Choice.IMPLICIT); 

} 

protected void startApp() { 
     display = Display.getDisplay(this); 
     optionsItem.append("TextField",null); 
     optionsItem.addCommand(exit); 
     optionsItem.setCommandListener(this); 
     display.setCurrent(optionsItem); 
} 

public void pauseApp() { 

} 

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

public void commandAction(Command c, Displayable d) { 


    } 
} 

回答

1

您是否正確初始化的成員變量?

Command對象是永遠不會被初始化,即「退出」爲空

private Command exit; 
+0

List的無參構造函數不存在。但是,我敢肯定,空命令是問題 – funkybro

+0

@funkybro謝謝你,我更新了答案 – eon

0

的價值屬性...錯誤似乎指向一些問題MIDlet JAD

看起來你的MIDlet甚至在未初始化的命令pointed to in previous answer得到執行機會之前安裝或啓動失敗。

要調試這樣的問題,我會使用最簡單的代碼,可能工作。像這樣說:

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

public class SmokeTest extends MIDlet { 

    protected void startApp() { 
     Display display = Display.getDisplay(this); 
     Form form = new Form("form"); 
     form.addCommand(new Command("Exit", Command.EXIT, 1)); 
     form.setCommandListener(new CommandListener() { 
      public void commandAction(Command c, Displayable d) { 
       notifyDestroyed(); 
      } 
     }); 
     display.setCurrent(form); 
    } 

    protected void pauseApp() { } 

    protected void destroyApp(boolean unconditional) { 
     notifyDestroyed(); 
    } 
} 

如果MIDlet的安裝並啓動OK,上面的代碼將顯示標題爲「形式」,並命令「退出」表單。如果這種情況沒有發生,最好研究一下Eclipse文檔以確定J2ME配置設置有什麼問題。

相關問題