2012-01-03 158 views
0

我打算在j2me開始我的第一課,我下載了一本簡單的書,並嘗試了我的第一個程序。 當我走第二步添加命令,我面臨着一個錯誤信息是:J2ME未捕獲異常

uncaught exception java/lang/noclassdeffounderror: readfile. 

所以,請你幫我理解這條消息?以及如何解決它? 請在下面找到我的代碼。

import javax.microedition.midlet.*; 
import javax.microedition.lcdui.*; 
public class ReadFile extends MIDlet implements CommandListener 
{ 
    private Form form1; 
    private Command Ok, Quit; 
    private Display display; 
    private TextField text1; 
    public void startApp() 
    { 
     form1 = new Form("TA_Pog"); 
     Ok = new Command("Ok", Command.OK, 1); 
     Quit = new Command("Quit", Command.EXIT, 2); 
     form1.setCommandListener(this); 
     form1.addCommand(Ok); 
     form1.addCommand(Quit); 
     text1 = new TextField("Put Your Name :","His Name : " , 32, TextField.URL); 
     form1.append(text1); 
     display = Display.getDisplay(this); 
     display.setCurrent(form1); 
    } 
    public void commandAction(Command c , Displayable d) 
    { 
     if (c == Ok) 
     { 
      Alert a = new Alert("Alert","This Alert from Ok Button", null, AlertType.ALARM); 
      a.setTimeout (3000); 
      display.setCurrent(a,this.form1); 
     } 
     else 
     { 
      this.notifyDestroyed(); 
     } 
    } 
    public void pauseApp() {} 
    public void destroyApp(boolean bool) {} 
} 

注意:上面的代碼完全取自一本書。

在此先感謝 BESR認爲

+0

你什麼時候得到這個例外 – 2012-01-03 08:23:40

回答

1
uncaught exception java/lang/noclassdeffounderror: readfile. 

我莫名其妙地懷疑該消息是完全按照你描述它。它看起來更像下面嗎?

uncaught exception java/lang/NoClassDefFoundError: ReadFile 

請記住在Java中使用小寫字母還是大寫字母都很重要。只要你不注意那樣的東西,你可能會遇到很多這樣的問題。

現在,仔細看看你的類名:

public class ReadFile //... 

您得到最有可能的例外說,Java的機器找不到您嘗試使用類。你的編譯/編譯有問題。

1

我運行你的代碼。它運行良好。我認爲你必須清理和建立你的項目。首先轉到項目屬性,然後轉到應用程序描述符並單擊Midlet選項卡,然後選擇您的midlet並按確定,然後清理構建,運行它。