Zxing Library java.lang.ExceptionInInitializerError

时间:2013-10-26 10:05:32

标签: android zxing

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

logcat的

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);

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

您可以按照以下链接

执行此操作

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

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