android (18)

来源:互联网 发布:mac os x lion 10.7.5 编辑:程序博客网 时间:2024/05/06 13:47
 

 

android (18)

0
 down vote favorite  I'm trying the Hello World example from http://android.git.kernel.org/?p=platform/dalvik.git;a=blob_plain;f=docs/hello-world.html;hb=HEAD

However, my Foo program did not run; dalvikvm complained about the following:

Dalvik VM unable to locate class 'Foo'

 java.lang.NoClassDefFoundError: Foo at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.ClassNotFoundException:
   Foo in loader dalvik.system.PathClassLoader[/mnt/sdcard/foo.jar] at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:573) at java.lang.ClassLoader.loadClass(ClassLoader.java:532) ... 1 more

Logcat gave more information during the dalvikvm invocation:

D/dalvikvm( 1361): creating instr width table E/dalvikvm( 1361): Can't open dex cache '/data/dalvik-cache/mnt@sdcard@foo.jar@classes.dex':
  No such file or directory I/dalvikvm( 1361):

 Unable to open or create cache for /mnt/sdcard/foo.jar (/data /dalvik-cache/mnt@sdcard@foo.jar@classes.dex) W/dalvikvm( 1361):
 
  threadid=1: thread exiting with uncaught exception (group=0x4 001e9a8)

Does anyone out there know what I did wrong? Thanks in advance.

-- Stephen

android dx
link|improve this question asked May 27 at 1:40
user761567
31
 
  

feedback 
2 Answersactive oldest votes  up vote
0
 down vote  It seems like you are trying to run it as a jar file from the sdcard. You need to use the tools to build it as an apk file.
 
  This converts from Java bytecodes to Dalvik codes, and reorganizes the contents of the file.
link|improve this answer answered May 27 at 1:44
Ted Hopp
17.5k1927
 
  If I'm not wrong, Android's dalvikvm can allow the execution of the converted dex file which I have JARed,
   following the Hello World example in the link that I've provided. So this should not be the reason. – user761567 May 27 at 1:54
 Hm. I just ran that example. I had to move the .class file to the platform-tools directory for dx to find it (on a Windows machine).
 
  But other than that, no problems. It sounds like your .jar file is corrupt somehow. – Ted Hopp May 27 at 2:30
 Hi Ted, thanks for trying to help me here... I wish to ascertain whether it's my jar file that's problematic,
 or is it my android device (Creative Ziio 8). Can you send me your email address at stephenchan@pmail.ntu.edu.sg s
 o that I can send to you my jar file so you can test for me? Also, what terminal emulation application are you using to access android command line? – user761567
  May 27 at 3:57
 I just open a command prompt and run adb shell. That gives me a shell session on the emulator. It works on a real device as well. (Email on the way.) –
 Ted Hopp May 27 at 13:58
 I see. When you said it worked earlier, did you try on a real device? I got the above results on a real device. – user761567 May 27 at 15:56

feedback 


 up vote
0
 down vote accepted  The author of the article, Andy McFadden, give me a tip:

"It's trying to create a .odex file in /data/dalvik-cache. You'll need to be running as root, or have an unprotected /data/dalvik-cache."

Once I rooted my device (e.g. using SuperOneClick), it worked!
 
所有的缓存都放在 data/dalvik-cache 中?