eclipse使用LWUIT时报错java.lang.NoClassDefFoundError解决方法

来源:互联网 发布:话不多但语出惊人知乎 编辑:程序博客网 时间:2024/04/30 06:32

本人的环境:eclipse3.3+eclipseme1.7.9+wtk2.5

测试源程序:

import com.sun.lwuit.Display;

import com.sun.lwuit.Form;

import com.sun.lwuit.Label;

import com.sun.lwuit.layouts.BorderLayout;

import com.sun.lwuit.plaf.UIManager;

import com.sun.lwuit.util.Resources;

 

public class Test extends javax.microedition.midlet.MIDlet {

   public void startApp() {

      // init the LWUIT Display

      Display.init(this);

      // Setting the application theme is discussed

      // later in the theme chapter and the resources chapter

     

      Form f = new Form();

      f.setTitle("Hello World");

      f.setLayout(new BorderLayout());

      f.addComponent("Center", new Label("I am a Label"));

      f.show();

   }

 

   public void pauseApp() {

   }

 

   public void destroyApp(boolean unconditional) {

   }

}

报错图如图1所示下:

1报错截图

 

解决方法:如图2所示

右击项目选择Properties->Java Build Path在右面的窗口中选择Order and Export, 点击Select All,选中里面的文件。

2 解决方法

程序运行成功的截图如图3所示:

  

3  程序运行成功

 

 

网上搜出来的解决方法2(经本人测试不行),在这里也写出来下:

order and export选卡旁边有Libraries       

       展开 LWUIT.jar           

       设置source attachment(双击即可设置)             

设置native library location

如果没有在order and export中全选,程序运行时也会报同样的错误。

还有就是经过网友测试,eclipse版本为3.4时测试不通过,程序通过以上设置后也会报同样的错误。

order and export作用:选择你要生成的或用来发布的类和文件从哪里取出来,一般默认就可以,但假如你有多个工程,或者有多个文件夹,这时你就需要选择!!!

问题产生原因

在设置eclispeme时:默认情况下 "source and outpub folder"项的 "project"为选中,我们修改这个默认设置,把"folders"选中

这样,就可以让eclipse把源代码和输出分离开。再看下order and export作用就应该明白了。

@@@@@@还有就是经过网友测试,eclipse版本为3.4时测试不通过,程序通过以上设置后也会报同样的错误。

最后,在项目打成JAR包时,要将LWUIT.jar文件一起打包,并且更改JAD文件,才能运行,这里就不在写了。

有问题请指正  QQ:250753635

 

 

原创粉丝点击