如何用Zxing 2.1库生成二维码?

时间:2013-01-05 13:07:59

标签: android zxing encode

问题:

好吧,我看过很多例子怎么做,但是在这个库中(Zxing 2.1)似乎没有用。我想将字符串编码为QRCode并获取位图以在Imageview中显示。

问题:

我应该使用旧版本吗?任何人都有Zxing库2.1的工作样本?

我尝试了什么:

String contents = uniqueID;
        BarcodeFormat barcodeFormat = BarcodeFormat.QR_CODE;

        int width = 300;
        int height = 300;

        MultiFormatWriter barcodeWriter = new MultiFormatWriter();
        try {
            BitMatrix matrix = barcodeWriter.encode(contents, barcodeFormat, width, height);


        } catch (WriterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

得到了这个:

01-05 13:02:10.701: E/AndroidRuntime(1375): FATAL EXCEPTION: main
01-05 13:02:10.701: E/AndroidRuntime(1375): java.lang.NoClassDefFoundError: com.google.zxing.BarcodeFormat
01-05 13:02:10.701: E/AndroidRuntime(1375):     at br.com.example.nightid.slidingsubmenu.IDcard.onCreate(IDcard.java:75)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at android.app.Activity.performCreate(Activity.java:4465)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at android.os.Looper.loop(Looper.java:137)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at android.app.ActivityThread.main(ActivityThread.java:4424)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at java.lang.reflect.Method.invokeNative(Native Method)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at java.lang.reflect.Method.invoke(Method.java:511)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-05 13:02:10.701: E/AndroidRuntime(1375):     at dalvik.system.NativeStart.main(Native Method)

抱歉,如果我犯了一个大错误,请第一次使用这个库。

1 个答案:

答案 0 :(得分:1)

它说它就在那里。您实际上并没有将这些类构建到您的应用中。与图书馆无关。