NoClassDefFoundError for code in an Java library on Android

前端 未结 24 1903
梦如初夏
梦如初夏 2020-11-22 15:19

I am experiencing an error quite often among my users. The app crashes during startup. When the MainActivity is supposed to be loaded the VM apparently cannot find the class

24条回答
  •  不思量自难忘°
    2020-11-22 15:49

    I encountered this NoClassDefFoundError when I used java.nio.charset.StandardCharsets.

    The reason is that StandardCharsets has not existed until JRE 1.7. If I make the java compile version set to 1.7, Eclipse complained that "Android requires compiler compliance level 5.0 or 6.0". So, I fixed it by right-click the project name->Android Tools->Fix Project Properties. It is compiled with JRE1.6.

    However, because StandardCharsets has not existed until 1.7. It reported NoClassDefFoundError when I ran it.

    I has not come to realize this until after trying a lot of other methods including reinstalling JDK. The real reason is clearly told by the meaning of NoClassDefFoundError: The class cannot be found at run time although it passed compilation.

    General conclusion is that as long as Android does not work with JRE 1.7, if you use any new feature provided since 1.7, you will encounter this error.

    My solution is that I copied those source code into my code!

提交回复
热议问题