Android: ClassNotFoundException while including ZXing

拟墨画扇 提交于 2019-12-04 03:51:27

问题


I know there are a lot of questions already. I've been going through all of them, but still I`m not able to solve my issue.

I was asked to extend an already existing android app, which is based on PhoneGap. I checked out the sources from a repo, and realized that the first developer included some library as dependency. i followed the instructions here, build in the core of ZXing isn't any build.xmlfor ant.

I went through the instructions at XZing Getting started, build my own core-2.3.jar tried to include, but failed. Same with the ready-deployed core.jar from the page

I included the the jars in the /libs folder, imported is a external jar, nothing worked. I`m getting following error everytime:

07-24 17:09:47.554: E/AndroidRuntime(8113): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{dev.tesobe.mobilepayment/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: Didn't find class "com.google.zxing.client.android.CaptureActivity" on path: /data/app/dev.tesobe.mobilepayment-1.apk
07-24 17:09:47.554: E/AndroidRuntime(8113):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at android.os.Looper.loop(Looper.java:137)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at android.app.ActivityThread.main(ActivityThread.java:5041)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at java.lang.reflect.Method.invokeNative(Native Method)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at java.lang.reflect.Method.invoke(Method.java:511)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at dalvik.system.NativeStart.main(Native Method)
07-24 17:09:47.554: E/AndroidRuntime(8113): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.zxing.client.android.CaptureActivity" on path: /data/app/dev.tesobe.mobilepayment-1.apk
07-24 17:09:47.554: E/AndroidRuntime(8113):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
07-24 17:09:47.554: E/AndroidRuntime(8113):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)

The manifest-declaration looks like this:

<!-- ZXing activities --> 
    <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" 
            android:exported="false"> 
        <intent-filter> 
            <action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity> 
    <activity android:name="com.google.zxing.client.android.encode.EncodeActivity" 
        android:label="@string/share_name"> 
        <intent-filter> 
            <action android:name="com.phonegap.plugins.barcodescanner.ENCODE"/> 
            <category android:name="android.intent.category.DEFAULT"/> 
        </intent-filter>
    </activity>

So, anyone any ideas, why I'm not able to include the CaptureActivity?


回答1:


You should ensure:

  • The ZXing Library is Added to your libs directory
  • Import the ZXing library in the properties/Build path
  • Ensure -- and this is the important part -- in the tab "Order and Export" that the Android Private Libraries is activated.

Normally, with the last Eclipse Android Plugins all this proccess is automatic when paste a jar inside the libs directory but there are some problems when add new libraries in old proyects. Try to enable the android private libraries.

ExtraBall: If you only want to capture barcodes you can try this fork of Zxing with the only indispensable of ZXing http://code.google.com/p/android-zxinglib/




回答2:


ISSUE SOLVED

Well... Stupid mistake. In the end I realized, that I didn't need to include the XZing Library jar. The guy who started the project included the PhoneGap Barcode Scanner Plugin which can be found here. Followed the instructions and everything is working well...



来源:https://stackoverflow.com/questions/17838203/android-classnotfoundexception-while-including-zxing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!