dx使用出現的錯誤總結

使用dx的各類悲劇錯誤,一直一直搞啊搞,後來在網上找到這篇文章才把這麼個小錯誤搞定。java

感謝原文做者的無私分享。 android

錯誤一:web

UNEXPECTED TOP-LEVEL EXCEPTION:  
java.lang.RuntimeException: abc.class: file not found  
        at com.android.dx.util.FileUtils.readFile(FileUtils.java:55)  
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.j  
ava:134)  
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java  
:109)  
        at com.android.dx.command.dexer.Main.processOne(Main.java:422)  
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)  
        at com.android.dx.command.dexer.Main.run(Main.java:209)  
        at com.android.dx.command.dexer.Main.main(Main.java:174)  
        at com.android.dx.command.Main.main(Main.java:91)  
1 error; aborting

當你出現這個運行時錯誤的話,那就是你須要編譯的文件須要和你安卓的platform-tool這個文件夾中的內容放在一塊兒this

你要作的就是把你的文件放在和dexdump.exe文件和dx.bat放在同一個目錄下spa

這個樣子就能夠編譯經過成功生成dex文件了code

錯誤二:orm

trouble processing:  
bad class file magic (cafebabe) or version (0033.0000)  
...while parsing Hello.class  
...while processing Hello.class  
1 warning  
no classfiles specified
  1. 也不知道這個代碼是怎麼寫的ip

以後我上網查了一下,我把JDK1.7換成了JDK1.6,但是仍是不行,出現了相同的提示,結果展現以下ci

這個時候解決的辦法有一個:get

強制轉換成1.6版本的class

使用的到的命令就是javac -source 1.6 -target 1.6  ****.java(****表明了你的java文件名稱)

具體步驟演示以下:

1.編寫一個java文件

2.使用javac命令:javac -source 1.6 -target 1.6 ******.java  注意你編寫的必須是在你的android的platform-tools文件目錄下

3.使用dx命令   dx  --dex --output =*****.dex  *****.class

dexdump.exe  -d *****.dex

這個時候咱們來看一下結果

D:\Android\android-sdk\platform-tools>dx --dex --output=abc.dex abc.class  
  
D:\Android\android-sdk\platform-tools>dexdump.exe -d abc.dex  
Processing 'abc.dex'...  
Opened 'abc.dex', DEX version '035'  
Class #0            -  
  Class descriptor  : 'Labc;'  
  Access flags      : 0x0001 (PUBLIC)  
  Superclass        : 'Ljava/lang/Object;'  
  Interfaces        -  
  Static fields     -  
  Instance fields   -  
  Direct methods    -  
    #0              : (in Labc;)  
      name          : '<init>'  
      type          : '()V'  
      access        : 0x10001 (PUBLIC CONSTRUCTOR)  
      code          -  
      registers     : 1  
      ins           : 1  
      outs          : 1  
      insns size    : 4 16-bit code units  
000160:                                        |[000160] abc.<init>:()V  
000170: 7010 0500 0000                         |0000: invoke-direct {v0}, Ljava/  
lang/Object;.<init>:()V // method@0005  
000176: 0e00                                   |0003: return-void  
      catches       : (none)  
      positions     :  
        0x0000 line=2  
      locals        :  
        0x0000 - 0x0004 reg=0 this Labc;  
  
    #1              : (in Labc;)  
      name          : 'main'  
      type          : '([Ljava/lang/String;)V'  
      access        : 0x0009 (PUBLIC STATIC)  
      code          -  
      registers     : 3  
      ins           : 1  
      outs          : 2  
      insns size    : 30 16-bit code units  
000178:                                        |[000178] abc.main:([Ljava/lang/S  
tring;)V  
000188: 1250                                   |0000: const/4 v0, #int 5 // #5  
00018a: 1271                                   |0001: const/4 v1, #int 7 // #7  
00018c: 2311 0600                              |0002: new-array v1, v1, [I // ty  
pe@0006  
000190: 2601 0800 0000                         |0004: fill-array-data v1, 000000  
0c // +00000008  
000196: 7120 0200 1000                         |0007: invoke-static {v0, v1}, La  
bc;.test:(I[I)V // method@0002  
00019c: 0e00                                   |000a: return-void  
00019e: 0000                                   |000b: nop // spacer  
0001a0: 0003 0400 0700 0000 0100 0000 0100 ... |000c: array-data (18 units)  
      catches       : (none)  
      positions     :  
        0x0000 line=18  
        0x000a line=19  
        0x000b line=18  
      locals        :  
  
    #2              : (in Labc;)  
      name          : 'test'  
      type          : '(I[I)V'  
      access        : 0x0089 (PUBLIC STATIC VARARGS)  
      code          -  
      registers     : 6  
      ins           : 2  
      outs          : 2  
      insns size    : 20 16-bit code units  
0001c4:                                        |[0001c4] abc.test:(I[I)V  
0001d4: 2151                                   |0000: array-length v1, v5  
0001d6: 1200                                   |0001: const/4 v0, #int 0 // #0  
0001d8: 3510 0c00                              |0002: if-ge v0, v1, 000e // +000  
c  
0001dc: 4402 0500                              |0004: aget v2, v5, v0  
0001e0: 6203 0000                              |0006: sget-object v3, Ljava/lang  
/System;.out:Ljava/io/PrintStream; // field@0000  
0001e4: 6e20 0300 2300                         |0008: invoke-virtual {v3, v2}, L  
java/io/PrintStream;.print:(I)V // method@0003  
0001ea: d800 0001                              |000b: add-int/lit8 v0, v0, #int  
1 // #01  
0001ee: 28f5                                   |000d: goto 0002 // -000b  
0001f0: 6200 0000                              |000e: sget-object v0, Ljava/lang  
/System;.out:Ljava/io/PrintStream; // field@0000  
0001f4: 6e20 0400 4000                         |0010: invoke-virtual {v0, v4}, L  
java/io/PrintStream;.println:(I)V // method@0004  
0001fa: 0e00                                   |0013: return-void  
      catches       : (none)  
      positions     :  
        0x0000 line=10  
        0x0006 line=12  
        0x000b line=10  
        0x000e line=14  
        0x0013 line=15  
      locals        :  
  
  Virtual methods   -  
  source_file_idx   : 12 (abc.java)
  1.  

以前走了好多彎路但願能幫上你們!^^

相關文章
相關標籤/搜索