java.lang.NoClassDefFoundError错误解决方法

在学习JSON例子时遇到此错误,错误内容:
08-06 03:57:43.515: E/AndroidRuntime(513): Uncaught handler: thread main exiting due to uncaught exception
08-06 03:57:43.523: E/AndroidRuntime(513): java.lang.NoClassDefFoundError: com.google.gson.stream.JsonReader
08-06 03:57:43.523: E/AndroidRuntime(513):         at mars.json01.JsonUtils.parseJson(JsonUtils.java:18)
08-06 03:57:43.523: E/AndroidRuntime(513):         at mars.json01.MainActivity$ButtonListener.onClick(MainActivity.java:28)
08-06 03:57:43.523: E/AndroidRuntime(513):         at android.view.View.performClick(View.java:2364)
……
……

在解决过程中参考了:http://www.jili360.com/home-space-uid-1618-do-blog-id-1257.html

This fixed it for me:

  • Remove all Android Library projects and external jars from the build path.
  • Create a folder named 'libs' in your project.
  • Place all external .jars in that folder, the ADT should now place them under 'Android Dependencies'.
  • Re-import all your previous Android Library projects the normal way.

The issue is that external jars are not placed in the 'libs' folder by default when using Properties - Java Build Path- Add External Jar, instead they are placed under 'Referenced Libraries' instead of 'Android Dependencies' and this causes the NoClassDefFoundError.

Please, check Dealing with dependencies in Android projects for more details.

解决方案:
问题原因:之前版本的ADT,把引入的包放在Referenced Libraries中,ADT升级到17后就出现了Android Dependencies,所以如果程序中引入的包没有在Android Dependencies中时,就会报文章开头的错。
解决方法:先移除之前的Referenced Libraries中的包,再将lib更名为libs,然后再将包重新复制到libs中,此时一般Android Dependencies就会自动出现,问题就解决了。但有的工程不自动出现,那就还需要进行下面一步的修改,见:http://blog.csdn.net/encienqi/article/details/7847858。
经过上面的方法,问题得到彻底解决!本人亲测!


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值