0

朋友们,我正在使用 zxing 2.2 lib 进行条码扫描。我看到了不同的教程。首先,当我在 eclips 中包含捕获活动库时。它显示错误..我找到了解决方案。并添加一个 core.jar 文件。错误成功消除。但是当我将捕获活动作为库时。它再次显示错误。我通过将 switch 语句转换为 if else 来删除它。现在库中没有错误。我将它包含在我的项目中..并使用代码扫描条形码..但它甚至没有打开相机并关闭我的应用程序..

// 这是我的主要活动代码...

       package com.bluehorn.diamondfusion;
        import android.os.Bundle;
        import android.app.Activity;
        import android.app.AlertDialog;
        import android.content.DialogInterface;
        import android.content.Intent;
        import android.view.Menu;
        import android.view.View;
        import android.widget.Button;

public class FusionMain extends Activity implements android.view.View.OnClickListener  {

        Button btnScan;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);   
    setContentView(R.layout.activity_main);
        btnScan=(Button)findViewById(R.id.btnScan);
        btnScan.setOnClickListener(this);
     }

        @Override
        public void onClick(View v) {
                if(v== btnScan){
          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
                   AlertDialog alert = new AlertDialog.Builder(FusionMain.this)
                   .create();
                     alert.setTitle("BarCode Result");
                     alert.setMessage(contents+"    \n        "+format);
                     alert.show();
                    }
                  else if (resultCode == RESULT_CANCELED) {
                       AlertDialog alert = new AlertDialog.Builder(FusionMain.this)
                        .create();
                     alert.setTitle("BarCode Result");
                     alert.setMessage("error  ,,,");
                     alert.show();
                  }

               }
            }
    }

// 这是我的 android manefist 文件代码

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bluehorn.diamondfusion"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="17"/>
     <uses-permission android:name="android.permission.CAMERA" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity android:name="com.google.zxing.client.android.CaptureActivity"
           android:screenOrientation="landscape"
           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.SCAN"/>
           <category android:name="android.intent.category.DEFAULT"/>
         </intent-filter>
        </activity>
        <activity
            android:name="com.bluehorn.diamondfusion.FusionMain"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

// 日志猫 ...

07-19 04:49:37.030: D/dalvikvm(3423): GC_EXTERNAL_ALLOC freed 50K, 51% free 2674K/5379K, external 1031K/1038K, paused 30ms
07-19 04:49:37.060: D/dalvikvm(3423): GC_EXTERNAL_ALLOC freed 3K, 51% free 2676K/5379K, external 1241K/1298K, paused 10ms
07-19 04:49:41.490: W/IInputConnectionWrapper(3423): showStatusIcon on inactive InputConnection
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to resolve static field 1322 (ISSUE_NUMBER) in Lcom/google/zxing/ResultMetadataType;
07-19 04:49:44.880: D/dalvikvm(3423): VFY: replacing opcode 0x62 at 0x0017
07-19 04:49:44.880: D/dalvikvm(3423): VFY: dead code 0x0019-0025 in Lcom/google/zxing/client/android/CaptureActivity;.<clinit> ()V
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/ResultPoint;)
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/ResultPoint;)
07-19 04:49:44.880: I/dalvikvm(3423): Could not find method com.google.zxing.ResultPoint.getX, referenced from method com.google.zxing.client.android.CaptureActivity.drawLine
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to resolve virtual method 4441: Lcom/google/zxing/ResultPoint;.getX ()F
07-19 04:49:44.880: D/dalvikvm(3423): VFY: replacing opcode 0x6e at 0x0004
07-19 04:49:44.880: D/dalvikvm(3423): VFY: dead code 0x0007-0020 in Lcom/google/zxing/client/android/CaptureActivity;.drawLine (Landroid/graphics/Canvas;Landroid/graphics/Paint;Lcom/google/zxing/ResultPoint;Lcom/google/zxing/ResultPoint;F)V
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: I/dalvikvm(3423): Could not find method com.google.zxing.Result.getResultPoints, referenced from method com.google.zxing.client.android.CaptureActivity.drawResultPoints
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to resolve virtual method 4437: Lcom/google/zxing/Result;.getResultPoints ()[Lcom/google/zxing/ResultPoint;
07-19 04:49:44.880: D/dalvikvm(3423): VFY: replacing opcode 0x6e at 0x0003
07-19 04:49:44.880: D/dalvikvm(3423): VFY: dead code 0x0006-0070 in Lcom/google/zxing/client/android/CaptureActivity;.drawResultPoints (Landroid/graphics/Bitmap;FLcom/google/zxing/Result;)V
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: I/dalvikvm(3423): Could not find method com.google.zxing.Result.toString, referenced from method com.google.zxing.client.android.CaptureActivity.handleDecodeExternally
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to resolve virtual method 4440: Lcom/google/zxing/Result;.toString ()Ljava/lang/String;
07-19 04:49:44.880: D/dalvikvm(3423): VFY: replacing opcode 0x74 at 0x00c9
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: D/dalvikvm(3423): VFY: dead code 0x00cc-0169 in Lcom/google/zxing/client/android/CaptureActivity;.handleDecodeExternally (Lcom/google/zxing/Result;Lcom/google/zxing/client/android/result/ResultHandler;Landroid/graphics/Bitmap;)V
07-19 04:49:44.880: D/dalvikvm(3423): VFY: dead code 0x0187-01a5 in Lcom/google/zxing/client/android/CaptureActivity;.handleDecodeExternally (Lcom/google/zxing/Result;Lcom/google/zxing/client/android/result/ResultHandler;Landroid/graphics/Bitmap;)V
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: I/dalvikvm(3423): Could not find method com.google.zxing.Result.getBarcodeFormat, referenced from method com.google.zxing.client.android.CaptureActivity.handleDecodeInternally
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to resolve virtual method 4434: Lcom/google/zxing/Result;.getBarcodeFormat ()Lcom/google/zxing/BarcodeFormat;
07-19 04:49:44.880: D/dalvikvm(3423): VFY: replacing opcode 0x74 at 0x004a
07-19 04:49:44.880: D/dalvikvm(3423): VFY: dead code 0x004d-01b3 in Lcom/google/zxing/client/android/CaptureActivity;.handleDecodeInternally (Lcom/google/zxing/Result;Lcom/google/zxing/client/android/result/ResultHandler;Landroid/graphics/Bitmap;)V
07-19 04:49:44.880: D/dalvikvm(3423): VFY: dead code 0x01bb-022a in Lcom/google/zxing/client/android/CaptureActivity;.handleDecodeInternally (Lcom/google/zxing/Result;Lcom/google/zxing/client/android/result/ResultHandler;Landroid/graphics/Bitmap;)V
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: I/dalvikvm(3423): Could not find method com.google.zxing.Result.getText, referenced from method com.google.zxing.client.android.CaptureActivity.handleDecode
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to resolve virtual method 4438: Lcom/google/zxing/Result;.getText ()Ljava/lang/String;
07-19 04:49:44.880: D/dalvikvm(3423): VFY: replacing opcode 0x6e at 0x006f
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: D/dalvikvm(3423): VFY: dead code 0x0072-0091 in Lcom/google/zxing/client/android/CaptureActivity;.handleDecode (Lcom/google/zxing/Result;Landroid/graphics/Bitmap;F)V
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: W/dalvikvm(3423): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
07-19 04:49:44.880: W/dalvikvm(3423): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/google/zxing/client/android/CaptureActivity;
07-19 04:49:44.880: W/dalvikvm(3423): Class init failed in newInstance call (Lcom/google/zxing/client/android/CaptureActivity;)
07-19 04:49:44.880: D/AndroidRuntime(3423): Shutting down VM
07-19 04:49:44.880: W/dalvikvm(3423): threadid=1: thread exiting with uncaught exception (group=0xb3f8c4f0)
07-19 04:49:44.880: D/AndroidRuntime(3423): procName from cmdline: com.bluehorn.diamondfusion
07-19 04:49:44.880: E/AndroidRuntime(3423): in writeCrashedAppName, pkgName :com.bluehorn.diamondfusion
07-19 04:49:44.880: D/AndroidRuntime(3423): file written successfully with content: com.bluehorn.diamondfusion StringBuffer : ;com.bluehorn.diamondfusion
07-19 04:49:44.890: I/Process(3423): Sending signal. PID: 3423 SIG: 9
07-19 04:49:44.890: E/AndroidRuntime(3423): FATAL EXCEPTION: main
07-19 04:49:44.890: E/AndroidRuntime(3423): java.lang.ExceptionInInitializerError
07-19 04:49:44.890: E/AndroidRuntime(3423):     at java.lang.Class.newInstanceImpl(Native Method)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at java.lang.Class.newInstance(Class.java:1409)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at android.os.Looper.loop(Looper.java:130)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at android.app.ActivityThread.main(ActivityThread.java:3683)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at java.lang.reflect.Method.invokeNative(Native Method)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at java.lang.reflect.Method.invoke(Method.java:507)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:638)
07-19 04:49:44.890: E/AndroidRuntime(3423):     at dalvik.system.NativeStart.main(Native Method)
07-19 04:49:44.890: E/AndroidRuntime(3423): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
07-19 04:49:44.890: E/AndroidRuntime(3423):     at com.google.zxing.client.android.CaptureActivity.<clinit>(CaptureActivity.java:97)
07-19 04:49:44.890: E/AndroidRuntime(3423):     ... 15 more
4

1 回答 1

-3

我认为这是构建路径的问题。右键单击您的项目,单击项目>属性>构建路径。单击订单和导出选项卡,然后检查所有库文件。让我知道它是否有效

于 2013-07-19T08:10:55.333 回答