月蚀:java.lang.NoClassDefFoundError的对JDK类的Andr​​oid项目 [英] Eclipse: java.lang.NoClassDefFoundError for JDK classes in an Android project

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

问题描述

首先,我要提一提,我读许多计算器有关职位的的NoClassDefFoundError ,我也读到它的很多其他博客和网站,但这些人提供的解决方案并没有解决它。

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

我写的,需要从JDK中的类来运行一个非常小的Andr​​oid应用程序。

我孤立的问题少了,通过创建一个新的Android应用工程是只有我的一个code :订单(在主类中的onCreate方法)重新创建它。该行:

  

BufferedImage中的buff =新的BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);

Eclipse将自动添加必要的导入:

  

导入java.awt.image.BufferedImage中;

不过问,我添加的罐子/ JRE这个类。

我添加了jdk1.6.0_38到Eclipse中的已安装的JRE(的像他们指示Eclipse帮助页面的)。

在该项目的Java构建路径我把它添加到添加库 - >JRE系统库 - >工作区缺省JRE。它会自动添加的JDK到项目的构建路径。

在编译的时候,我没有得到任何错误。运行在Android模拟器(AVD任何)我得到以下错误的应用程序只有当:

  E / dalvikvm(828):找不到类的java.awt.image.BufferedImage中,从法com.example.usejdk.MainActivity.onCreate引用
W / dalvikvm(828):VFY:无法解析新的实例467(Ljava / AWT /图像/ BufferedImage中)在LCOM /例子/ usejdk / MainActivity;
D / dalvikvm(828):VFY:更换运code输入0x22为0x0009
D / dalvikvm(828):DexOpt:无法在选择中的0x0C LCOM /例子/ usejdk / MainActivity直接调用0x0cdc; .onCreate
D / AndroidRuntime(828):关闭虚拟机
W / dalvikvm(828):主题ID = 1:螺纹退出与未捕获的异常(组= 0x40a70930)
E / AndroidRuntime(828):致命异常:主要
E / AndroidRuntime(828):java.lang.NoClassDefFoundError的:java.awt.image.BufferedImage中
E / AndroidRuntime(828):在com.example.usejdk.MainActivity.onCreate(MainActivity.java:16)
E / AndroidRuntime(828):在android.app.Activity.performCreate(Activity.java:5104)
E / AndroidRuntime(828):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
E / AndroidRuntime(828):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
E / AndroidRuntime(828):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E / AndroidRuntime(828):在android.app.ActivityThread.access $ 600(ActivityThread.java:141)
E / AndroidRuntime(828):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1234)
E / AndroidRuntime(828):在android.os.Handler.dispatchMessage(Handler.java:99)
E / AndroidRuntime(828):在android.os.Looper.loop(Looper.java:137)
E / AndroidRuntime(828):在android.app.ActivityThread.main(ActivityThread.java:5039)
E / AndroidRuntime(828):在java.lang.reflect.Method.invokeNative(本机方法)
E / AndroidRuntime(828):在java.lang.reflect.Method.invoke(Method.java:511)
E / AndroidRuntime(828):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)
E / AndroidRuntime(828):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E / AndroidRuntime(828):在dalvik.system.NativeStart.main(本机方法)
 

下面事情是我试过的没有工作

  1. 加入到的eclipse.ini 的JDK的位置(-vm /usr/lib/jvm/jdk1.6.0_38/bin在2个独立的行)。
  2. 我添加的路径-Djava.library.path = / usr / lib中/ JVM / jdk1.6.0_38 / JRE / lib目录。
  3. 默认VM参数
  4. 使用32位JRE和JDK和JRE / JDK7 - 没有工作(当然)
  5. 在我尝试添加的jdk jar文件的手动到库文件夹,并注明添加到构建路径 - 没有工作
  6. 在我卸载,并与ADT重新安装了Eclipse和Android SDK ...

没有解决这个恼人的错误...

请,也注意到这些:

  1. 在我确信我的的.classpath 文件包含默认JRE条目(<一href="http://maven.apache.org/plugins/maven-eclipse-plugin/trouble-shooting/jdk-being-used-is-different-than-expected.html"相对=nofollow>像他们说这里)
  2. 在我尝试添加其他 jar文件的库文件夹+添加到路径,并利用它们 - 它工作得很好
  3. 在我尝试运行使用相同的code(一号线)导入java.awt.image.BufferedImage中;在常规 Java项目(不是一个Android项目),并取得了该项目使用默认JRE - 它的工作得很好为什么呢!在一个普通的Java项目的Andr​​oid项目的工作,而不是?

我想这意味着我的Eclipse安装确实必须使用JDK类的能力,而不是Android应用程序

那么,我必须做的,使code运行的这一行在Android应用程序

任何帮助将是非常,非常AP preciated。感谢名单提前。

解决方案
  

那么,我必须做的,使code运行这个单行在Android应用程序?

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

不知道你需要什么的BufferedImage 的,这是很难说有什么替代方案,你应该考虑。最有可能你试图做一些涉及到图像的单个像素越来越接入图像处理的?如果是这样的话,有一个看 位图 和<一href="http://developer.android.com/reference/android/graphics/BitmapFactory.html"><$c$c>BitmapFactory类。

这一切都归结为的Java SDK!=的Andr​​oid SDK 。不管怎么说,也可以考虑在这里做一个搜索的SO;你不是第一个犯这样的错误。

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.

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).

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

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);

Eclipse automatically adds the necessary import:

import java.awt.image.BufferedImage;

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

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

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.

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)

Here are the things I tried that didn't work:

  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...

Please, also notice these:

  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?

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

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

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

解决方案

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

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.

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.

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.

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

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