关于升级ADT22后出现java.lang.ClassNotFoundException错误的解决

来源:互联网 发布:sql语句的关键字 编辑:程序博客网 时间:2024/04/29 07:39

今天打开刚打开Eclipse,提示我library库有更新。二话没说,直接打开Android SDK Manager,更新了一遍所有能更新的,同时把ADT也升级到了22版本。
升级过程比较顺利,编译之前的代码,也没有什么问题,但是接下来就出问题了。

我把编译出来的APK在设备上运行,一运行就出来java.lang.ClassNotFoundException的错误,明明那个class是存在的。之前也遇到过类似的问题,但那个是升级ADT17的时候外部jar包包含不对引起的,这个不是同一个问题啊,但是从现象上来看应该是一样的。

既然错误的信息一样,那就从引用的地方入手。后来果然发现.classpath文件发生了变化。

之前的.classpath文件:

<?xml version="1.0" encoding="UTF-8"?><classpath><classpathentry kind="src" path="src"/><classpathentry kind="src" path="gen"/><classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/><classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/><classpathentry kind="output" path="bin/classes"/></classpath>

升级后重新编译且运行出现错误的.classpath文件:

<?xml version="1.0" encoding="UTF-8"?><classpath><classpathentry kind="src" path="src"/><classpathentry kind="src" path="gen"/><classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/><classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/><classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/><classpathentry kind="output" path="bin/classes"/></classpath>

后来我新建了一个工程,发现.classpath文件如下:

<?xml version="1.0" encoding="UTF-8"?><classpath><classpathentry kind="src" path="src"/><classpathentry kind="src" path="gen"/><classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/><classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/><classpathentry kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/><classpathentry kind="output" path="bin/classes"/></classpath>

区别就在于将

<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/><classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
改成了

<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/><classpathentry kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>

修改后再次运行,OK,没问题了!



原创粉丝点击