生成qrcode时的ActivityNotFoundException

时间:2012-10-12 05:53:01

标签: android android-activity qr-code

我试图通过意图生成qrcode,但我总是得到ActivityNotFoundException。我的lib中有我的core.jar。

这是我的代码:

intent = new Intent("com.google.zxing.client.android.ENCODE");
    intent.putExtra("ENCODE_TYPE", "TEXT_TYPE");
    intent.putExtra("ENCODE_DATA", "Hello World!");
    startActivity(intent);

这是日志:

10-12 20:47:09.457: E/AndroidRuntime(1347): FATAL EXCEPTION: main
10-12 20:47:09.457: E/AndroidRuntime(1347): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sampleqrcode/com.example.sampleqrcode.MainActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.ENCODE cat=[android.intent.category.DEFAULT] (has extras) }
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.os.Looper.loop(Looper.java:137)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.ActivityThread.main(ActivityThread.java:4424)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at java.lang.reflect.Method.invokeNative(Native Method)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at java.lang.reflect.Method.invoke(Method.java:511)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at dalvik.system.NativeStart.main(Native Method)
10-12 20:47:09.457: E/AndroidRuntime(1347): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.ENCODE cat=[android.intent.category.DEFAULT] (has extras) }
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.Activity.startActivityForResult(Activity.java:3190)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.Activity.startActivity(Activity.java:3297)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at com.example.sampleqrcode.MainActivity.onCreate(MainActivity.java:24)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.Activity.performCreate(Activity.java:4465)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-12 20:47:09.457: E/AndroidRuntime(1347):     ... 11 more

我错过了什么吗?

2 个答案:

答案 0 :(得分:0)

  1. here导入工作区中的zxing库项目。

  2. 从库项目创建一个新项目。它会正常工作。

    您也可以访问此link进行实施。

答案 1 :(得分:0)

这表示未安装条形码扫描仪。您负责捕获ActivityNotFoundException并对其进行处理,例如提示用户安装它。

更好的是,使用原始zxing项目中的android-integration代码。这是两个类,它在一个简单的API中包含了所有这些细节。 http://code.google.com/p/zxing/wiki/ScanningViaIntent