将zxing导入现有项目

时间:2012-10-29 13:38:50

标签: android

我试图将ZXing导入到我正在开发的Android应用程序中,但每当我尝试启动该活动时,它都会崩溃。

 public void bcreader(View view)
{
    Intent intent = new Intent("com.google.zxing.client.android.SCAN");
    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
    startActivityForResult(intent, 0);
}

public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
       if (requestCode == 0) 
       {
          if (resultCode == RESULT_OK) 
          {
             String contents = intent.getStringExtra("SCAN_RESULT");
             String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
             // Handle successful scan
          } else if (resultCode == RESULT_CANCELED) 
          {
             // Handle cancel
          }
       }
}

我的MainActivity左侧有ZXing源。 我遵循了this教程,但无济于事。 我确保已导入所有文件,并将com.google.zxing ...设置为库等。 我还确保manifest.xml具有相应的权限。

谁能告诉我我做错了什么?

错误日志:
10-30 00:26:06.919:D / AndroidRuntime(4194):关闭VM 10-30 00:26:06.919:W / dalvikvm(4194):threadid = 1:线程退出,未捕获异常(group = 0x40a261f8) 10-30 00:26:06.919:E / AndroidRuntime(4194):致命异常:主要 10-30 00:26:06.919:E / AndroidRuntime(4194):java.lang.RuntimeException:无法实例化活动ComponentInfo {com.google.zxing.client.android/com.google.zxing.client.android.CaptureActivity} :java.lang.ClassNotFoundException:com.google.zxing.client.android.CaptureActivity 10-30 00:26:06.919:E / AndroidRuntime(4194):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1993) 10-30 00:26:06.919:E / AndroidRuntime(4194):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104) 10-30 00:26:06.919:E / AndroidRuntime(4194):在android.app.ActivityThread.access $ 600(ActivityThread.java:132) 10-30 00:26:06.919:E / AndroidRuntime(4194):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1157) 10-30 00:26:06.919:E / AndroidRuntime(4194):在android.os.Handler.dispatchMessage(Handler.java:99) 10-30 00:26:06.919:E / AndroidRuntime(4194):在android.os.Looper.loop(Looper.java:137) 10-30 00:26:06.919:E / AndroidRuntime(4194):在android.app.ActivityThread.main(ActivityThread.java:4575) 10-30 00:26:06.919:E / AndroidRuntime(4194):at java.lang.reflect.Method.invokeNative(Native Method) 10-30 00:26:06.919:E / AndroidRuntime(4194):at java.lang.reflect.Method.invoke(Method.java:511) 10-30 00:26:06.919:E / AndroidRuntime(4194):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:789) 10-30 00:26:06.919:E / AndroidRuntime(4194):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 10-30 00:26:06.919:E / AndroidRuntime(4194):at dalvik.system.NativeStart.main(Native Method) 10-30 00:26:06.919:E / AndroidRuntime(4194):引起:java.lang.ClassNotFoundException:com.google.zxing.client.android.CaptureActivity 10-30 00:26:06.919:E / AndroidRuntime(4194):at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 10-30 00:26:06.919:E / AndroidRuntime(4194):at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 10-30 00:26:06.919:E / AndroidRuntime(4194):at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 10-30 00:26:06.919:E / AndroidRuntime(4194):在android.app.Instrumentation.newActivity(Instrumentation.java:1023) 10-30 00:26:06.919:E / AndroidRuntime(4194):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1984) 10-30 00:26:06.919:E / AndroidRuntime(4194):... 11更多 10-30 00:29:27.799:D / AndroidRuntime(4407):关闭VM 10-30 00:29:27.799:W / dalvikvm(4407):threadid = 1:线程退出时未捕获异常(group = 0x40a261f8) 10-30 00:29:27.799:E / AndroidRuntime(4407):致命异常:主要 10-30 00:29:27.799:E / AndroidRuntime(4407):java.lang.RuntimeException:无法实例化活动ComponentInfo {com.google.zxing.client.android/com.google.zxing.client.android.CaptureActivity} :java.lang.ClassNotFoundException:com.google.zxing.client.android.CaptureActivity 10-30 00:29:27.799:E / AndroidRuntime(4407):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1993) 10-30 00:29:27.799:E / AndroidRuntime(4407):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104) 10-30 00:29:27.799:E / AndroidRuntime(4407):在android.app.ActivityThread.access $ 600(ActivityThread.java:132) 10-30 00:29:27.799:E / AndroidRuntime(4407):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1157) 10-30 00:29:27.799:E / AndroidRuntime(4407):在android.os.Handler.dispatchMessage(Handler.java:99) 10-30 00:29:27.799:E / AndroidRuntime(4407):在android.os.Looper.loop(Looper.java:137) 10-30 00:29:27.799:E / AndroidRuntime(4407):在android.app.ActivityThread.main(ActivityThread.java:4575) 10-30 00:29:27.799:E / AndroidRuntime(4407):at java.lang.reflect.Method.invokeNative(Native Method) 10-30 00:29:27.799:E / AndroidRuntime(4407):at java.lang.reflect.Method.invoke(Method.java:511) 10-30 00:29:27.799:E / AndroidRuntime(4407):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:789) 10-30 00:29:27.799:E / AndroidRuntime(4407):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 10-30 00:29:27.799:E / AndroidRuntime(4407):at dalvik.system.NativeStart.main(Native Method) 10-30 00:29:27.799:E / AndroidRuntime(4407):引起:java.lang.ClassNotFoundException:com.google.zxing.client.android.CaptureActivity 10-30 00:29:27.799:E / AndroidRuntime(4407):at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 10-30 00:29:27.799:E / AndroidRuntime(4407):at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 10-30 00:29:27.799:E / AndroidRuntime(4407):at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 10-30 00:29:27.799:E / AndroidRuntime(4407):在android.app.Instrumentation.newActivity(Instrumentation.java:1023) 10-30 00:29:27.799:E / AndroidRuntime(4407):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1984) 10-30 00:29:27.799:E / AndroidRuntime(4407):... 11 more

1 个答案:

答案 0 :(得分:1)

将以下内容添加到清单中。

        <activity
        android:name="com.google.zxing.client.android.CaptureActivity"
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="landscape"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:windowSoftInputMode="stateAlwaysHidden" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.google.zxing.client.android.SCAN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.google.zxing.client.android.encode.EncodeActivity"
        android:configChanges="orientation|keyboardHidden"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:windowSoftInputMode="stateAlwaysHidden" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.google.zxing.client.android.ENCODE" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>