Question

I am trying to incorporate ZXing into my own android app via intent, and am having difficulty. I can compile my code fine, but when it tries to call the following after a button click it dies on the IntentIntegrator() constructor:

public void ScanCheck(View view){

try{
IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
integrator.initiateScan();
}catch(Exception e){

return;
}        

}

the above code is verbatim and MainActivity is the name of my class. I typically program in C# or C++ via a Visual Studio IDE so it is entirely possible that my problem could be in either my java code or in my eclipse project set up.

I am using Eclipse Kepler Service Release 2

The Phone is running Android 2.2.2

The android-integration-3.0.0.jar file has been added to the project Java build path as an external JAR.

The android-integration-3.0.0 file has been imported underneath the /lib folder of the project.

I am also importing the zxing package via the following line of code

import com.google.zxing.integration.android.*;

The error message makes me believe that I have missed giving Eclipse something it needs to run effectively, but I am out of ideas.

I have looked at: Class not found when using zxing

and

How to create for IntentIntegrator in Android with zXing

and

android zxing intentintegrator

along with a slew of other generic ZXING posts here trying to solve this.

I am including the logcat dump below from the point of error.

04-18 17:34:46.301: E/AndroidRuntime(8074): FATAL EXCEPTION: main
04-18 17:34:46.301: E/AndroidRuntime(8074): java.lang.IllegalStateException: Could not execute method of the activity
04-18 17:34:46.301: E/AndroidRuntime(8074):     at android.view.View$1.onClick(View.java:2072)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at android.view.View.performClick(View.java:2408)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at android.view.View$PerformClick.run(View.java:8816)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at android.os.Handler.handleCallback(Handler.java:587)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at android.os.Looper.loop(Looper.java:123)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at java.lang.reflect.Method.invokeNative(Native Method)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at java.lang.reflect.Method.invoke(Method.java:521)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:893)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:651)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at dalvik.system.NativeStart.main(Native Method)
04-18 17:34:46.301: E/AndroidRuntime(8074): Caused by: java.lang.reflect.InvocationTargetException
04-18 17:34:46.301: E/AndroidRuntime(8074):     at tcom.example.test.MainActivity.ScanCheck(MainActivity.java:76)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at java.lang.reflect.Method.invokeNative(Native Method)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at java.lang.reflect.Method.invoke(Method.java:521)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at android.view.View$1.onClick(View.java:2067)
04-18 17:34:46.301: E/AndroidRuntime(8074):     ... 11 more
04-18 17:34:46.301: E/AndroidRuntime(8074): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.integration.android.IntentIntegrator
04-18 17:34:46.301: E/AndroidRuntime(8074):     ... 15 more
04-18 17:34:46.301: E/AndroidRuntime(8074): Caused by: java.lang.ClassNotFoundException: com.google.zxing.integration.android.IntentIntegrator in loader dalvik.system.PathClassLoader[/data/app/tcom.example.test-2.apk]
04-18 17:34:46.301: E/AndroidRuntime(8074):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-18 17:34:46.301: E/AndroidRuntime(8074):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-18 17:34:46.301: E/AndroidRuntime(8074):     ... 15 more

EDIT:

here is the button's xml

<Button
android:layout_width="wrap_content"     
android:layout_height="wrap_content"
android:text="@string/button_send" 
android:onClick="ScanCheck"/>

Running it again I found the following error that I missed last time:

04-19 10:47:57.805: E/dalvikvm(2664): Could not find class 'com.google.zxing.integration.android.IntentIntegrator', referenced from method tcom.example.test.MainActivity.ScanCheck

again the jar has been added to the java build path and to the lib folder (well that import created a series of sub folders under lib in which the library resides)

I also noted that the Integrator class makes calls to some fragement methods that require honeycomb or higher. I am targeting Android 2.2.2, but am inexperienced enough at java / android to not know whether or not that presents a problem since things are being pulled from a JAR file. I suspect it is a problem. and am hoping that there is an easy fix.

Was it helpful?

Solution

So it turns out the problem was with the way that I was adding the library to Eclipse. I was right clicking the /libs folder, and importing the file into the project. On the import page where you select the type of file you are importing I clicked "Archive" which seemed to make sense for a "Java ARchive" file. This is wrong the way I finally got it to work was to:

place the .jar file into my workspace/project/libs folder on the filesystem side

open project in Eclipse

right click /libs

select import

select "File System"

select the /libs folder

select the jar file

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top