在进行 Android vogella SQLite 教程时,我遇到了以下烦人的错误:
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”会出现在“com.example.de.vogella.android”中。这是一种标准生成的名称吗?在这个项目中,我的所有包/名称/路径从未以“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
通常情况下,应用程序启动,但从一开始就崩溃,并输出以下内容:
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>
我刚开始学习安卓开发,所以可能会有一些简单的东西被忽略了。
非常感谢。
编辑 更改 <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