错误“由:java.lang.ClassNotFoundException:”引起
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18638078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error "Caused by: java.lang.ClassNotFoundException:"
提问by Jacob
During android vogella tutorial regarding to sqlite I have encountered annoying problem with following error:
在关于sqlite的android vogella教程中,我遇到了以下错误的烦人问题:
09-05 09:18:06.127: E/AndroidRuntime(981): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.de.vogella.android.todos.contentprovider.MyTodoContentProvider" on path: DexPathList[[zip file "/data/app/com.example.de.vogella.android.todos-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.de.vogella.android.todos-1, /system/lib]]
I followed many times step by step modyfying all files to have R. class properly recreated. The very strange thing about this errror is that I have no idea why there is anything about "com.example" in "com.example.de.vogella.android". Is this some kind of standard generated name? All my packages/names/paths never started with "com.example"(In this project). I checked all files and cant find issue.
我多次一步一步地修改所有文件以正确重新创建 R. 类。这个错误非常奇怪的是,我不知道为什么“com.example.de.vogella.android”中有关于“com.example”的任何内容。这是某种标准生成的名称吗?我所有的包/名称/路径都从未以“com.example”开头(在这个项目中)。我检查了所有文件,但找不到问题。
More output from LogCat:
LogCat 的更多输出:
09-05 09:18:06.127: E/AndroidRuntime(981): FATAL EXCEPTION: main
09-05 09:18:06.127: E/AndroidRuntime(981): java.lang.RuntimeException: Unable to get provider com.example.de.vogella.android.todos.contentprovider.MyTodoContentProvider: java.lang.ClassNotFoundException: Didn't find class "com.example.de.vogella.android.todos.contentprovider.MyTodoContentProvider" on path: DexPathList[[zip file "/data/app/com.example.de.vogella.android.todos-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.de.vogella.android.todos-1, /system/lib]]
09-05 09:18:06.127: E/AndroidRuntime(981): at android.app.ActivityThread.installProvider(ActivityThread.java:4882)
09-05 09:18:06.127: E/AndroidRuntime(981): at android.app.ActivityThread.installContentProviders(ActivityThread.java:4485)
09-05 09:18:06.127: E/AndroidRuntime(981): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4425)
09-05 09:18:06.127: E/AndroidRuntime(981): at android.app.ActivityThread.access00(ActivityThread.java:141)
09-05 09:18:06.127: E/AndroidRuntime(981): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
09-05 09:18:06.127: E/AndroidRuntime(981): at android.os.Handler.dispatchMessage(Handler.java:99)
09-05 09:18:06.127: E/AndroidRuntime(981): at android.os.Looper.loop(Looper.java:137)
09-05 09:18:06.127: E/AndroidRuntime(981): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-05 09:18:06.127: E/AndroidRuntime(981): at java.lang.reflect.Method.invokeNative(Native Method)
09-05 09:18:06.127: E/AndroidRuntime(981): at java.lang.reflect.Method.invoke(Method.java:525)
09-05 09:18:06.127: E/AndroidRuntime(981): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-05 09:18:06.127: E/AndroidRuntime(981): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-05 09:18:06.127: E/AndroidRuntime(981): at dalvik.system.NativeStart.main(Native Method)
09-05 09:18:06.127: E/AndroidRuntime(981): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.de.vogella.android.todos.contentprovider.MyTodoContentProvider" on path: DexPathList[[zip file "/data/app/com.example.de.vogella.android.todos-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.de.vogella.android.todos-1, /system/lib]]
09-05 09:18:06.127: E/AndroidRuntime(981): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
09-05 09:18:06.127: E/AndroidRuntime(981): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
09-05 09:18:06.127: E/AndroidRuntime(981): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
09-05 09:18:06.127: E/AndroidRuntime(981): at android.app.ActivityThread.installProvider(ActivityThread.java:4867)
09-05 09:18:06.127: E/AndroidRuntime(981): ... 12 more
09-05 09:18:06.156: E/ActivityThread(950): Failed to find provider info for de.vogella.android.todos.contentprovider
In generall application starts but gets crash from the beginning with output:
一般来说,应用程序启动但从输出开始就崩溃了:
Unfortunatelly, {AppName} has stopped.
My AndroidManifest.xml looks like this
我的 AndroidManifest.xml 看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.vogella.android.todos"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/reminder"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".TodosOverviewActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TodoDetailActivity"
android:windowSoftInputMode="stateVisible|adjustResize"
android:label="@string/title_activity_todo_detail" >
</activity>
<provider
android:name=".contentprovider.MyTodoContentProvider"
android:authorities="de.vogella.android.todos.contentproviderxxxxxxx" >
</provider>
</application>
</manifest>
I have just started with android so I guese there is something trivial missing.
我刚刚开始使用 android,所以我想缺少一些微不足道的东西。
Thanks a lot.
非常感谢。
EDITChange of <provider>
to:
编辑更改<provider>
为:
<provider
android:name=".contentprovider.MyTodoContentProvider"
android:authorities="de.vogella.android.todos.contentprovider" >
</provider>
results in :
结果是 :
Installation error: INSTALL_FAILED_CONFLICTING_PROVIDER
Please check logcat output for more details.
Launch canceled!
with LogCat:
使用 LogCat:
09-06 02:02:38.198: E/AndroidRuntime(864): FATAL EXCEPTION: main
09-06 02:02:38.198: E/AndroidRuntime(864): java.lang.RuntimeException: Unable to get provider com.example.de.vogella.android.todos.contentprovider.MyTodoContentProvider: java.lang.ClassNotFoundException: Didn't find class "com.example.de.vogella.android.todos.contentprovider.MyTodoContentProvider" on path: DexPathList[[zip file "/data/app/com.example.de.vogella.android.todos-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.de.vogella.android.todos-1, /system/lib]]
09-06 02:02:38.198: E/AndroidRuntime(864): at android.app.ActivityThread.installProvider(ActivityThread.java:4882)
09-06 02:02:38.198: E/AndroidRuntime(864): at android.app.ActivityThread.installContentProviders(ActivityThread.java:4485)
09-06 02:02:38.198: E/AndroidRuntime(864): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4425)
09-06 02:02:38.198: E/AndroidRuntime(864): at android.app.ActivityThread.access00(ActivityThread.java:141)
09-06 02:02:38.198: E/AndroidRuntime(864): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
09-06 02:02:38.198: E/AndroidRuntime(864): at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 02:02:38.198: E/AndroidRuntime(864): at android.os.Looper.loop(Looper.java:137)
09-06 02:02:38.198: E/AndroidRuntime(864): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-06 02:02:38.198: E/AndroidRuntime(864): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 02:02:38.198: E/AndroidRuntime(864): at java.lang.reflect.Method.invoke(Method.java:525)
09-06 02:02:38.198: E/AndroidRuntime(864): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-06 02:02:38.198: E/AndroidRuntime(864): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-06 02:02:38.198: E/AndroidRuntime(864): at dalvik.system.NativeStart.main(Native Method)
09-06 02:02:38.198: E/AndroidRuntime(864): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.de.vogella.android.todos.contentprovider.MyTodoContentProvider" on path: DexPathList[[zip file "/data/app/com.example.de.vogella.android.todos-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.de.vogella.android.todos-1, /system/lib]]
09-06 02:02:38.198: E/AndroidRuntime(864): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
09-06 02:02:38.198: E/AndroidRuntime(864): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
09-06 02:02:38.198: E/AndroidRuntime(864): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
09-06 02:02:38.198: E/AndroidRuntime(864): at android.app.ActivityThread.installProvider(ActivityThread.java:4867)
09-06 02:02:38.198: E/AndroidRuntime(864): ... 12 more
09-06 02:02:38.236: E/ActivityThread(834): Failed to find provider info for de.vogella.android.todos.contentprovider
采纳答案by user2554058
I had this problem once. The code was working previously and suddenly it stopped working (crash at app startup) when I synced and built an older version of the code.
我曾经遇到过这个问题。该代码以前可以正常工作,但当我同步并构建旧版本的代码时,它突然停止工作(应用程序启动时崩溃)。
The fix was to just close and restart Eclipse and clean the project and clean all the dependent library projects. Then it started working properly again.
解决方法是关闭并重新启动 Eclipse 并清理项目并清理所有依赖库项目。然后它又开始正常工作了。
It's some sort of build problem in Eclipse, when refreshing the project files.
刷新项目文件时,这是 Eclipse 中的某种构建问题。
Update: In particular, if you've accidentally modified the ".classpath" file (to revert to an older version), Eclipse/Android SDK can get confused and not build the project properly. When you restart Eclipse and clean the project, Eclipse will re-modify the ".classpath" file, and build properly.
更新:特别是,如果您不小心修改了“.classpath”文件(以恢复到旧版本),Eclipse/Android SDK 可能会混淆并且无法正确构建项目。当您重新启动 Eclipse 并清理项目时,Eclipse 将重新修改“.classpath”文件,并正确构建。
回答by Salman Khakwani
Change this line in your Code :
在您的代码中更改这一行:
<provider
android:name="de.vogella.android.todos.contentprovider.MyTodoContentProvider"
android:authorities="de.vogella.android.todos.contentproviderxxxxxxx" >
</provider>
Your problem will be solved.
您的问题将得到解决。
回答by Paul
Dont forget to declare the content provider in your Manifest.
不要忘记在您的清单中声明内容提供者。
回答by Aksel Fatih
No com.example is not a standard package name, It is generated according to the AndroidManifest.xmlfile that is located at the root of the project.
没有com.example不是标准的包名,是根据项目根目录下的AndroidManifest.xml文件生成的。
At the manifest file there is an attribute called package which gives the application a unique name.
在清单文件中有一个名为 package 的属性,它为应用程序提供了一个唯一的名称。
Please check the manifest file and to my best guess, fix the packageattribute as
请检查清单文件,并根据我的最佳猜测,将包属性修复为
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.vogella.android.todos"