[英]Eclipse Android Project Throws Class Not Found Error During Runtime
I am trying to incorporate ZXing into my own android app via intent, and am having difficulty. 我试图通过意图将ZXing合并到我自己的android应用中,并且遇到了困难。 I can compile my code fine, but when it tries to call the following after a button click it dies on the IntentIntegrator() constructor:
我可以很好地编译代码,但是当单击按钮后尝试调用以下代码时,它将死于IntentIntegrator()构造函数:
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. 上面的代码是逐字记录的,MainActivity是我的班级的名称。 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.
我通常通过Visual Studio IDE用C#或C ++进行编程,因此我的问题很可能是我的Java代码或Eclipse项目设置中的问题。
I am using Eclipse Kepler Service Release 2 我正在使用Eclipse Kepler Service Release 2
The Phone is running Android 2.2.2 手机正在运行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. android-integration-3.0.0.jar文件已作为外部JAR添加到项目Java构建路径中。
The android-integration-3.0.0 file has been imported underneath the /lib folder of the project. android-integration-3.0.0文件已导入到项目的/ lib文件夹下。
I am also importing the zxing package via the following line of code 我也通过以下代码行导入zxing包
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. 错误消息使我相信我错过了为Eclipse提供有效运行所需的功能的想法,但是我没有主意。
I have looked at: Class not found when using zxing 我看过: 使用zxing时找不到类
and 和
How to create for IntentIntegrator in Android with zXing 如何使用zXing在Android中为IntentIntegrator创建
and 和
android zxing intentintegrator Android Zxing IntentIntegrator
along with a slew of other generic ZXING posts here trying to solve this. 以及许多其他通用ZXING帖子,试图解决此问题。
I am including the logcat dump below from the point of error. 从错误的角度来看,我包括下面的logcat转储。
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 这是按钮的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 04-19 10:47:57.805:E / dalvikvm(2664):找不到从方法tcom.example.test.MainActivity.ScanCheck引用的类'com.google.zxing.integration.android.IntentIntegrator'
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) 再次将jar添加到Java构建路径和lib文件夹(以及import会在库所在的lib下创建一系列子文件夹)
I also noted that the Integrator class makes calls to some fragement methods that require honeycomb or higher. 我还注意到,Integrator类调用某些需要蜂窝或更高版本的细分方法。 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.
我的目标是Android 2.2.2,但是在Java / android上没有足够的经验,因为从JAR文件中提取内容,所以不知道是否存在问题。 I suspect it is a problem.
我怀疑这是一个问题。 and am hoping that there is an easy fix.
并希望有一个简单的解决方法。
So it turns out the problem was with the way that I was adding the library to Eclipse. 因此事实证明问题出在我将库添加到Eclipse的方式上。 I was right clicking the /libs folder, and importing the file into the project.
我右键单击/ libs文件夹,然后将文件导入到项目中。 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.
在您选择要导入的文件类型的导入页面上,我单击了“归档”,这似乎对“ Java ARchive”文件有意义。 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 将.jar文件放入文件系统侧的我的工作空间/ project / libs文件夹中
open project in Eclipse 在Eclipse中打开项目
right click /libs 右键单击/ libs
select import 选择导入
select "File System" 选择“文件系统”
select the /libs folder 选择/ libs文件夹
select the jar file 选择jar文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.