【Android QR Code】开源项目:ZXing(一)导入项目
作者:互联网
维基百科:QR Code
http://en.wikipedia.org/wiki/QR_code
开源项目:ZXing
http://code.google.com/p/zxing/
1、下载源代码
导航栏,选择Downloads
下载当前最新版本
2、导入项目
解压下载的.zip文件
打开Eclipse,菜单栏,选择file -> new -> project...
在弹出的New Project对话框中,选择Android -> Android Project from Existing Code,点击Next
Root Directory文本框,点击Browse按钮,选择zxing/android文件夹,点击Finish
3、排错
错误1:导入的项目,红叉报错,无法运行
打开报错的文件,错误的原因是没有找到类文件
解决的方法:添加core.jar包
在Package Explorer选择导入的项目,右键 -> Build Path -> Add External Archives...
选择zxing/core目录下的core.jar
错误2:运行项目,应用异常退出
查看logcat,内容如下所示:
11-26 13:21:37.044: E/AndroidRuntime(16533): FATAL EXCEPTION: main
11-26 13:21:37.044: E/AndroidRuntime(16533): java.lang.ExceptionInInitializerError
11-26 13:21:37.044: E/AndroidRuntime(16533): at java.lang.Class.newInstanceImpl(Native Method)
11-26 13:21:37.044: E/AndroidRuntime(16533): at java.lang.Class.newInstance(Class.java:1429)
11-26 13:21:37.044: E/AndroidRuntime(16533): at android.app.Instrumentation.newActivity(Instrumentation.java:1036)
11-26 13:21:37.044: E/AndroidRuntime(16533): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2701)
11-26 13:21:37.044: E/AndroidRuntime(16533): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
11-26 13:21:37.044: E/AndroidRuntime(16533): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
11-26 13:21:37.044: E/AndroidRuntime(16533): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
11-26 13:21:37.044: E/AndroidRuntime(16533): at android.os.Handler.dispatchMessage(Handler.java:99)
11-26 13:21:37.044: E/AndroidRuntime(16533): at android.os.Looper.loop(Looper.java:144)
11-26 13:21:37.044: E/AndroidRuntime(16533): at android.app.ActivityThread.main(ActivityThread.java:4937)
11-26 13:21:37.044: E/AndroidRuntime(16533): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 13:21:37.044: E/AndroidRuntime(16533): at java.lang.reflect.Method.invoke(Method.java:521)
11-26 13:21:37.044: E/AndroidRuntime(16533): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-26 13:21:37.044: E/AndroidRuntime(16533): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-26 13:21:37.044: E/AndroidRuntime(16533): at dalvik.system.NativeStart.main(Native Method)
11-26 13:21:37.044: E/AndroidRuntime(16533): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
11-26 13:21:37.044: E/AndroidRuntime(16533): at com.google.zxing.client.android.CaptureActivity.<clinit>(CaptureActivity.java:101)
11-26 13:21:37.044: E/AndroidRuntime(16533): ... 15 more
解决方法:调整Order and Export
在Package Explorer选择导入的项目,右键 -> Build Path -> Configure Build Path...
在弹出的对话框中,选择Order and Export选项卡,勾选core.jar并置顶
运行截图:
测试,扫描维基百科上提供的二维码
运行结果:
转载于:https://www.cnblogs.com/dyingbleed/archive/2012/11/26/2789098.html
标签:16533,26,Code,21,13,ZXing,37.044,QR,AndroidRuntime 来源: https://blog.csdn.net/weixin_33970449/article/details/94335235