在学习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。
经过上面的方法,问题得到彻底解决!本人亲测!