Eclipse:Android项目中的JDK类的java.lang.NoClassDefFoundError [英] Eclipse: java.lang.NoClassDefFoundError for JDK classes in an Android project

查看:336
本文介绍了Eclipse:Android项目中的JDK类的java.lang.NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想提一下,我读了许多 stackoverflow文章关于 NoClassDefFoundError ,我也在许多其他博客和网站,但人们提供的解决方案没有解决它。

First, I want to mention that I read many stackoverflow posts about NoClassDefFoundError, and I also read about it in many other blogs and websites, but the solutions that people offered didn't fix it.

我正在使用ADT插件版本v21运行 Eclipse 64位。 0.1-543035在 Ubuntu 12.10 64位。一切都是64位,Ubuntu,Eclipse和我使用的JRE和JDK(jdk1.6.0_38)。

I am running Eclipse 64-bit with the ADT plugin version v21.0.1-543035 on Ubuntu 12.10 64-bit. Everything is 64-bit, Ubuntu, Eclipse and the JRE and JDK that I use (jdk1.6.0_38).

我写了一个非常小的Android应用程序,需要一个类从JDK运行。

I wrote a very small Android App that needs a class from the JDK to run.

我把这个问题解决了一些,并通过创建一个新的Android应用程序项目来重新创建,只有一条我的代码(在onCreate方法的主类中)。这行:

I isolated the problem a little, and recreated it by creating a new "Android Application Project" with ONLY ONE LINE OF MY CODE (in the main class in the onCreate method). This line:


BufferedImage buff = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);

BufferedImage buff = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);

Eclipse自动添加必要的导入:

Eclipse automatically adds the necessary import:


import java.awt.image.BufferedImage; / p>

import java.awt.image.BufferedImage;

但是要求我为这个类添加jars / JRE。

but asks that I add the jars/JRE for this class.

我在已安装的JRE(就像他们在Eclipse帮助页面上指示)。

I added the jdk1.6.0_38 to Eclipse in "Installed JREs" (like they instruct on the Eclipse help pages).

在项目的Java构建路径中,我通过添加库 - >JRE系统库 - >工作区默认JRE。它自动将JDK添加到项目的构建路径。

In the project's "Java Build Path" I added it through "Add library" -> "JRE system library" -> "Workspace default JRE". It automatically added the JDK to the project's build path.

在编译期间,我没有收到错误。只有在Android模拟器(任何AVD)中运行应用程序时,才会收到以下错误:

During compile time, I get no errors. Only when running the application in the android emulator (any AVD) I get the following error:

E/dalvikvm(828): Could not find class 'java.awt.image.BufferedImage', referenced from method com.example.usejdk.MainActivity.onCreate
W/dalvikvm(828): VFY: unable to resolve new-instance 467 (Ljava/awt/image/BufferedImage;) in Lcom/example/usejdk/MainActivity;
D/dalvikvm(828): VFY: replacing opcode 0x22 at 0x0009
D/dalvikvm(828): DexOpt: unable to opt direct call 0x0cdc at 0x0c in Lcom/example/usejdk/MainActivity;.onCreate
D/AndroidRuntime(828): Shutting down VM
W/dalvikvm(828): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
E/AndroidRuntime(828): FATAL EXCEPTION: main
E/AndroidRuntime(828):   java.lang.NoClassDefFoundError: java.awt.image.BufferedImage
E/AndroidRuntime(828):   at com.example.usejdk.MainActivity.onCreate(MainActivity.java:16)
E/AndroidRuntime(828):   at android.app.Activity.performCreate(Activity.java:5104)
E/AndroidRuntime(828):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
E/AndroidRuntime(828):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
E/AndroidRuntime(828):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime(828):   at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime(828):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime(828):   at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(828):   at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(828):   at android.app.ActivityThread.main(ActivityThread.java:5039)
E/AndroidRuntime(828):   at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(828):   at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(828):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime(828):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime(828):   at dalvik.system.NativeStart.main(Native Method)

以下是我尝试过的 didn' t


  1. 添加到 eclipse.ini jdk的位置(-vm
    /usr/lib/jvm/jdk1.6.0_38/bin分为两行)。

  2. 我添加了路径-Djava.library.path = / usr / lib / jvm / jdk1.6.0_38 / jre / lib的默认VM参数。

  3. 使用32位JRE和JDK和JRE / JDK7 - 当然不行。

  4. 我尝试添加jdk jar文件手动到libs文件夹并标记添加到buildpath - 没有工作。

  5. 我用ADT和Android SDK卸载并安装了Eclipse ...

  1. adding to "eclipse.ini" the location of the jdk ("-vm /usr/lib/jvm/jdk1.6.0_38/bin" in 2 separate lines).
  2. I added the "Default VM Arguments" of the path "-Djava.library.path=/usr/lib/jvm/jdk1.6.0_38/jre/lib".
  3. Using 32-bit JREs and JDKs and JRE/JDK7 - didn't work (of course).
  4. I tried adding the jdk jar files manually to the "libs" folder and mark "add to buildpath" - didn't work.
  5. I uninstalled and installed Eclipse again with the ADT and Android SDK...

没有什么可以修复这个烦人的错误...

Nothing fixes this annoying error...

请注意这些:


  1. 我确定我的 .classpath 文件包含默认的JRE条目(喜欢他们在这里说

  2. 我尝试向其添加其他 jar文件elibs文件夹+添加到路径,并使用它们 - 它工作正常。

  3. 我尝试使用import java.awt运行相同的代码(一行) image.BufferedImage;在常规 java项目(而不是Android项目)中,使项目使用默认JRE,并且正常工作!为什么工作在一个REGULAR Java项目,而不是一个Android项目?

  1. I made sure my .classpath file contains the default JRE entry (like they say here)
  2. I tried adding other jar files to the "libs" folder + "add to path", and using them - it worked fine.
  3. I tried running the same code (the one line) using the "import java.awt.image.BufferedImage;" in a regular java project (not an android project) and made the project "use Default JRE" - and it worked fine! Why does it work on a REGULAR Java project and not in an Android project?

我想这意味着我的Eclipse安装 strong>有能力使用jdk类,但不在Android应用程序中。

I guess it means that my Eclipse installation does have the ability to use the jdk classes, but not in android applications.

那么我要做什么来做这个一行代码在android应用程序中运行

So what do I have to do to make this single line of code run in an android application?

任何帮助都将非常受赞赏。 Thanx提前。

Any help would be VERY-VERY appreciated. Thanx in advance.

推荐答案


那么我要做什么来做这个单行代码在Android应用程序中运行?

So what do I have to do to make this single line of code run in an android application?

简短的答案是:没有,因为你不能/ />做任何事情关于它。整个 java.awt。* 框架不是Android SDK的一部分,包括 BufferedImage ,因此不被支持由仿真器或物理设备。 Android有自己的加载和渲染图形的实现。

The short answer is: nothing, because you can't do anything about it. The whole java.awt.* framework isn't part of the Android SDK, including BufferedImage, and hence not supported by the emulator or physical devices. Android has its own implementation for loading and rendering graphics.

不知道你需要什么 BufferedImage ,很难说你应该考虑什么办法很可能你想要做一些图像处理,包括访问图像的各个像素?如果是这样,请查看 位图 BitmapFactory 课程。

Without knowing what you need BufferedImage for, it's hard to say what alternative you should be considering. Most likely you're trying to do some sort of image manipulation that involves getting access to the individual pixels of an image? If that's the case, have a look at the Bitmap and BitmapFactory classes.

所有这些都归结为 Java SDK!= Android SDK 。无论如何,也考虑在这里搜索SO;你不是第一个犯这个错误的人。

It all boils down to Java SDK != Android SDK. Anyways, also consider doing a search here on SO; you're not the first one to make this mistake.

这篇关于Eclipse:Android项目中的JDK类的java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆