2012-08-13 102 views
0

我不喜欢买Android的OnBarcode库,当我收到电子邮件说我需要下载我有一个.jar文件,我将该文件添加到我的应用程序中创建的lib文件夹。然后我去了我的项目的属性,我去了“Java构建路径”,我将jar文件添加到我的应用程序中。接下来,我添加了一些代码插入视图类,并在onDraw有部分我加testQRCode(canvas)的代码是安装和使用OnBarcode库

private static void testQRCode(Canvas canvas) throws Exception 
    { 
     QRCode barcode = new QRCode(); 

     barcode.setData("test;"); 
     barcode.setDataMode(QRCode.M_AUTO); 
     barcode.setVersion(1); 
     barcode.setEcl(QRCode.ECL_L); 

     barcode.setFnc1Mode(IBarcode.FNC1_NONE); 

     barcode.setProcessTilde(false); 

     barcode.setUom(IBarcode.UOM_PIXEL); 
     barcode.setX(3f); 

     barcode.setLeftMargin(50f); 
     barcode.setRightMargin(50f); 
     barcode.setTopMargin(50f); 
     barcode.setBottomMargin(50f); 
     barcode.setResolution(72); 

     barcode.setForeColor(AndroidColor.black); 
     barcode.setBackColor(AndroidColor.white); 

     RectF bounds = new RectF(0, 0, 100, 100); 
     barcode.drawBarcode(canvas, bounds); 
    } 

,当我尝试运行我的应用程序,我得到的是说java.lang.NoClassDefFoundError: com.onbarcode.barcode.android.QRCode我做了一个错误的finaly错了我有点强调我们在这一点上,因为这800美元的购买成本和它的崩溃在吓跑我。你们对我做错了什么有什么想法吗?谢谢。

+0

“然后,我去了我的项目的属性,我去了”Java构建路径“,我将这个jar文件添加到我的应用程序中,就像那样” - 如果您在R16或更新版本的Eclipse的ADT插件,这一步是不需要的,可能会导致问题。只需将JAR添加到'libs /'目录(注意复数)就足够了。 – CommonsWare 2012-08-13 12:23:27

+0

谢谢,你解决了我的问题! – 2012-08-13 12:37:09

回答

1

可以试试这个:

-> Right click on your project 
-> Go into Build Path 
-> Configure Build Path 
-> Go to Order and Export 
-> Check your OnBarcode library 
-> Clean your project 

它解决我的问题,当我尝试添加一个图书馆,我也得到了同样的错误喜欢你。

+0

我应该在“订单和导出”中看到哪里是干净的,因为在底部只有确定并取消 – 2012-08-13 12:34:21

+0

检查完库后,单击确定。然后在屏幕顶部的Eclipse工具栏上,单击Project - > Clean - > Check your project - > click Ok – 2012-08-13 12:36:53

0

您是否将.jar文件添加到项目的“libs”目录中?如果没有,添加它,在eclipse中刷新项目,右键单击.jar文件,然后单击构建路径>添加到构建路径。

+0

我是第一次做到这一点,现在我只是重新做到了,而且我仍然遇到同样的错误。 – 2012-08-13 12:28:32