Eclipse的Android项目抛出类未找到错误在运行时 [英] Eclipse Android Project Throws Class Not Found Error During Runtime
问题描述
我试图通过意向合并ZXing到我自己的Android应用程序,和我有困难。我可以编译我的code很好,但是当它试图一个按钮后,调用下面点击它死在IntentIntegrator()构造函数:
公共无效ScanCheck(查看视图){尝试{
IntentIntegrator积分=新IntentIntegrator(MainActivity.this);
integrator.initiateScan();
}赶上(例外五){返回;
}}
以上code是逐字记录和MainActivity是我的类的名称。
我通常在C#或C ++通过Visual Studio IDE中的程序,因此是完全可能的,我的问题可能在任我的Java code或设置我的Eclipse项目。
我使用Eclipse开普勒服务发布2
手机运行的是Android 2.2.2
Android的整合-3.0.0.jar文件添加为外部JAR项目的Java构建路径。
Android的整合-3.0.0文件已经导入了项目的/ lib文件夹下面。
我也通过code的以下行
导入斑马线包 进口com.google.zxing.integration.android *。
错误信息让我相信,我已经错过了给Eclipse的东西,它需要有效地运行,但我的想法。
我已经看过:
类没有发现使用时zxing
和
<一个href=\"http://stackoverflow.com/questions/12074316/how-to-create-for-intentintegrator-in-android-with-zxing\">How创建IntentIntegrator在Android中使用zXing
和
在这里等通用ZXING职位摆试图解决这个一起。
我,包括从logcat中错误的点以下转储。
04-18 17:34:46.301:E / AndroidRuntime(8074):致命异常:主要
04-18 17:34:46.301:E / AndroidRuntime(8074):java.lang.IllegalStateException:无法执行活动的方法
04-18 17:34:46.301:E / AndroidRuntime(8074):在android.view.View $ 1.onClick(View.java:2072)
04-18 17:34:46.301:E / AndroidRuntime(8074):在android.view.View.performClick(View.java:2408)
04-18 17:34:46.301:E / AndroidRuntime(8074):在android.view.View $ PerformClick.run(View.java:8816)
04-18 17:34:46.301:E / AndroidRuntime(8074):在android.os.Handler.handleCallback(Handler.java:587)
04-18 17:34:46.301:E / AndroidRuntime(8074):在android.os.Handler.dispatchMessage(Handler.java:92)
04-18 17:34:46.301:E / AndroidRuntime(8074):在android.os.Looper.loop(Looper.java:123)
04-18 17:34:46.301:E / AndroidRuntime(8074):在android.app.ActivityThread.main(ActivityThread.java:4627)
04-18 17:34:46.301:E / AndroidRuntime(8074):在java.lang.reflect.Method.invokeNative(本机方法)
04-18 17:34:46.301:E / AndroidRuntime(8074):在java.lang.reflect.Method.invoke(Method.java:521)
04-18 17:34:46.301:E / AndroidRuntime(8074):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:893)
04-18 17:34:46.301:E / AndroidRuntime(8074):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:651)
04-18 17:34:46.301:E / AndroidRuntime(8074):在dalvik.system.NativeStart.main(本机方法)
04-18 17:34:46.301:E / AndroidRuntime(8074):因:java.lang.reflect.InvocationTargetException
04-18 17:34:46.301:E / AndroidRuntime(8074):在tcom.example.test.MainActivity.ScanCheck(MainActivity.java:76)
04-18 17:34:46.301:E / AndroidRuntime(8074):在java.lang.reflect.Method.invokeNative(本机方法)
04-18 17:34:46.301:E / AndroidRuntime(8074):在java.lang.reflect.Method.invoke(Method.java:521)
04-18 17:34:46.301:E / AndroidRuntime(8074):在android.view.View $ 1.onClick(View.java:2067)
04-18 17:34:46.301:E / AndroidRuntime(8074):11 ...更多
04-18 17:34:46.301:E / AndroidRuntime(8074):java.lang.NoClassDefFoundError的:产生的原因com.google.zxing.integration.android.IntentIntegrator
04-18 17:34:46.301:E / AndroidRuntime(8074):15 ...更多
04-18 17:34:46.301:E / AndroidRuntime(8074):抛出java.lang.ClassNotFoundException:致com.google.zxing.integration.android.IntentIntegrator装载机dalvik.system.PathClassLoader [/数据/应用/ TCOM .example.test-2.apk]
04-18 17:34:46.301:E / AndroidRuntime(8074):在dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-18 17:34:46.301:E / AndroidRuntime(8074):在java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-18 17:34:46.301:E / AndroidRuntime(8074):在java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-18 17:34:46.301:E / AndroidRuntime(8074):15 ...更多
编辑:
这里是按钮的XML
&LT;按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/ button_send
安卓的onClick =ScanCheck/&GT;
再次运行它,我发现下面的错误,我错过了最后一次:
10月4日至19日:47:57.805:E / dalvikvm(2664):找不到类的com.google.zxing.integration.android.IntentIntegrator,从法tcom.example.test.MainActivity.ScanCheck <引用/ p>
再罐子已经被添加到Java构建路径和lib文件夹
(清楚,在进口中的库所在的lib创建一系列的子文件夹)我还指出,集成类使得到需要蜂窝或更高一些fragement方法的调用。我瞄准的Android 2.2.2,但我是java / Android的足够经验的不知道,因为事情正在从一个JAR文件的拉升$ P $与否psents一个问题。我怀疑这是一个问题。 ,我希望有一个简单的办法。
因此,原来的问题是与我加入到Eclipse的图书馆该怎么走。我右键单击/ libs文件夹,并且将文件导入到项目中。你在哪里选择文件类型的导入页要导入我点击这似乎是有道理的Java归档文件归档。 这是错误的的路上我终于它得到的工作是:
.jar文件放到我的工作区/项目/ libs文件夹上的文件系统侧
打开项目在Eclipse
右键单击/库
选择进口
选择文件系统
选择/ libs文件夹
选择jar文件
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.
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
这篇关于Eclipse的Android项目抛出类未找到错误在运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!