在关于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]]
我多次一步一步地修改所有文件,以便正确地重新创建R.类。关于这个错误的一个非常奇怪的事情是我不知道为什么“com.example.de.vogella.android”中有关于“com.example”的内容。这是某种标准生成的名称吗?我的所有包/名称/路径都不是以“com.example”开头的(在这个项目中)。我检查了所有文件,无法找到问题。
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.access$1300(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
在generall应用程序启动但是从输出开始崩溃:
Unfortunatelly, {AppName} has stopped.
我的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>
我刚刚开始使用android所以我猜测有一些微不足道的缺失。
非常感谢。
修改
将<provider>
更改为:
<provider
android:name=".contentprovider.MyTodoContentProvider"
android:authorities="de.vogella.android.todos.contentprovider" >
</provider>
结果:
Installation error: INSTALL_FAILED_CONFLICTING_PROVIDER
Please check logcat output for more details.
Launch canceled!
使用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.access$1300(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
答案 0 :(得分:10)
我曾经遇到过这个问题。该代码之前正在工作,当我同步并构建旧版本的代码时,它突然停止工作(在应用启动时崩溃)。
修复只是关闭并重新启动Eclipse并清理项目并清理所有依赖库项目。然后它又开始正常工作了。
在刷新项目文件时,这是Eclipse中的某种构建问题。
更新:特别是,如果您不小心修改了“.classpath”文件(恢复到旧版本),Eclipse / Android SDK可能会混淆并且无法正确构建项目。当您重新启动Eclipse并清理项目时,Eclipse将重新修改“.classpath”文件,并正确构建。
答案 1 :(得分:1)
在您的代码中更改此行:
<provider
android:name="de.vogella.android.todos.contentprovider.MyTodoContentProvider"
android:authorities="de.vogella.android.todos.contentproviderxxxxxxx" >
</provider>
你的问题将得到解决。
答案 2 :(得分:1)
别忘了在你的Manifest中声明内容提供者。
答案 3 :(得分:0)
没有com.example不是标准软件包名称,它是根据位于项目根目录的 AndroidManifest.xml 文件生成的。
在清单文件中有一个名为package的属性,它为应用程序提供了唯一的名称。
请检查清单文件并最好猜测,将包属性修复为
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.vogella.android.todos"