0

我正在使用 ZXing 库我已经从从 code.google.com 下载的 ZXing 文件夹中导入了“android”项目并使其成为库,还将 core.jar 文件添加到库中。当我运行它强制关闭的应用程序时,

日志猫

10-26 15:16:58.495: E/AndroidRuntime(21673): FATAL EXCEPTION: main
10-26 15:16:58.495: E/AndroidRuntime(21673): java.lang.ExceptionInInitializerError
10-26 15:16:58.495: E/AndroidRuntime(21673):    at java.lang.Class.newInstanceImpl(Native Method)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at java.lang.Class.newInstance(Class.java:1429)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2583)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at android.app.ActivityThread.access$2300(ActivityThread.java:126)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at android.os.Looper.loop(Looper.java:123)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at android.app.ActivityThread.main(ActivityThread.java:4633)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at java.lang.reflect.Method.invokeNative(Native Method)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at java.lang.reflect.Method.invoke(Method.java:521)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-26 15:16:58.495: E/AndroidRuntime(21673):    at dalvik.system.NativeStart.main(Native Method)
10-26 15:16:58.495: E/AndroidRuntime(21673): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
10-26 15:16:58.495: E/AndroidRuntime(21673):    at com.google.zxing.client.android.CaptureActivity.<clinit>(CaptureActivity.java:97)

menifest.xml 文件内容为

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />



    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="in.blogspot.khurram2java.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <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>
    </application>

    </manifest>



MainActivity.java


Intent intent = new Intent(MainActivity.this,CaptureActivity.class);
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
4

2 回答 2

0

答案就在那里:NoClassDefFoundError. 您实际上并没有在应用程序中包含库类。

另外,请不要复制android/并用作克隆。按原样使用我们的名称/UI/命名空间甚至是不合法的。

于 2013-10-26T10:11:41.180 回答
0

您可以通过以下链接执行此操作

https://stackoverflow.com/a/19293128/958850

但是,不建议将示例项目用作库项目。

于 2013-10-26T18:08:13.657 回答