1. 程式人生 > >Android studio 開發中遇到問題

Android studio 開發中遇到問題

1.錯誤 com.android.dex.util.ExceptionWithContext

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.util.ExceptionWithContext
	at com.android.dex.util.ExceptionWithContext.withContext(ExceptionWithContext.java:45)
	at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:369)
	at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137)
	at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93)
	at com.android.dx.command.dexer.Main.processClass(Main.java:729)
	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
	at com.android.dx.command.dexer.Main.access$300(Main.java:83)
	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)
	at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
	at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
	at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
	at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
	at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
	at com.android.dx.command.dexer.Main.processOne(Main.java:632)
	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
	at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
	at com.android.dx.command.dexer.Main.run(Main.java:246)
	at com.android.dx.command.dexer.Main.main(Main.java:215)
	at com.android.dx.command.Main.main(Main.java:106)
Caused by: java.lang.NullPointerException
	at com.android.dx.cf.code.ConcreteMethod.<init>(ConcreteMethod.java:87)
	at com.android.dx.cf.code.ConcreteMethod.<init>(ConcreteMethod.java:75)
	at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:271)
	... 22 more
...while processing <init> (Lcom/koabc/launcher/Launcher;)V
...while processing com/koabc/launcher/Launcher$1.class
1 error; aborting
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\develop\Java\bin\java.exe'' finished with non-zero exit value 1

dex 編譯BUG,出現情況一般會有以下兩個條件,有例項化的內部類,有一個if條件的程式碼塊,並且這個if條件是一個常量(final 修飾,通常值為false)

解決方法:調整程式碼結構或去掉if程式碼塊或讓其值為true