Eclipse - 不幸的是应用程序已停止 - ClassNotFoundException:在路径上找不到类
Posted
技术标签:
【中文标题】Eclipse - 不幸的是应用程序已停止 - ClassNotFoundException:在路径上找不到类【英文标题】:Eclipse - unfortunately app has stopped - ClassNotFoundException: Didn't find class on path 【发布时间】:2016-02-12 04:30:19 【问题描述】:我是 android 新手,还在学习 java、xml 等。这是我的第一个项目,但仍然出错。在模拟器中说:“不幸的是应用程序已停止”..我需要帮助..请...!!
Logcat的错误日志
11-10 22:42:28.700: E/AndroidRuntime(1627): FATAL EXCEPTION: main
11-10 22:42:28.700: E/AndroidRuntime(1627): Process: id.co.kendaricall, PID: 1627
11-10 22:42:28.700: E/AndroidRuntime(1627): java.lang.RuntimeException: Unable to instantiate activity ComponentInfoid.co.kendaricall/id.co.kendaricall.KategoryActivity: java.lang.ClassNotFoundException: Didn't find class "id.co.kendaricall.KategoryActivity" on path: DexPathList[[zip file "/data/app/id.co.kendaricall-2.apk"],nativeLibraryDirectories=[/data/app-lib/id.co.kendaricall-2, /system/lib]]
11-10 22:42:28.700: E/AndroidRuntime(1627): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
11-10 22:42:28.700: E/AndroidRuntime(1627): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
11-10 22:42:28.700: E/AndroidRuntime(1627): at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-10 22:42:28.700: E/AndroidRuntime(1627): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-10 22:42:28.700: E/AndroidRuntime(1627): at android.os.Handler.dispatchMessage(Handler.java:102)
11-10 22:42:28.700: E/AndroidRuntime(1627): at android.os.Looper.loop(Looper.java:136)
11-10 22:42:28.700: E/AndroidRuntime(1627): at android.app.ActivityThread.main(ActivityThread.java:5001)
11-10 22:42:28.700: E/AndroidRuntime(1627): at java.lang.reflect.Method.invokeNative(Native Method)
11-10 22:42:28.700: E/AndroidRuntime(1627): at java.lang.reflect.Method.invoke(Method.java:515)
11-10 22:42:28.700: E/AndroidRuntime(1627): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-10 22:42:28.700: E/AndroidRuntime(1627): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-10 22:42:28.700: E/AndroidRuntime(1627): at dalvik.system.NativeStart.main(Native Method)
11-10 22:42:28.700: E/AndroidRuntime(1627): Caused by: java.lang.ClassNotFoundException: Didn't find class "id.co.kendaricall.KategoryActivity" on path: DexPathList[[zip file "/data/app/id.co.kendaricall-2.apk"],nativeLibraryDirectories=[/data/app-lib/id.co.kendaricall-2, /system/lib]]
11-10 22:42:28.700: E/AndroidRuntime(1627): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-10 22:42:28.700: E/AndroidRuntime(1627): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
11-10 22:42:28.700: E/AndroidRuntime(1627): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
11-10 22:42:28.700: E/AndroidRuntime(1627): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
11-10 22:42:28.700: E/AndroidRuntime(1627): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
11-10 22:42:28.700: E/AndroidRuntime(1627): ... 11 more
这是 manifest.xml 文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="id.co.kendaricall"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/KendariCallTheme">
<uses-library android:name="com.google.android.maps"
android:required="false" />
<activity android:name=".KategoryActivity"
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=".KontakDetailActivity" />
<activity android:name=".SettingActivity" />
<activity android:name=".TemplateActivity" />
<activity android:name=".KontakListActivity" />
<activity android:name=".PencarianActivity" />
<activity android:name=".KontakFavoritActivity" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CALL_PRIVILEDGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>
【问题讨论】:
例外正是它所说的。它找不到类。是否正确命名了 KategoryActivity 类并在正确的包中?它甚至存在吗? 【参考方案1】:我认为所有旅游活动课程都放在任何其他包中。转到 id.co.kendaricall 文件夹并检查是否存在天气活动类。如果没有,则找到所有类保存的文件夹。假设所有类都保存在包 id.co.kendaricall.activity 中,所以在清单中进行更改
<activity android:name="activity.KontakDetailActivity" />
<activity android:name="activity.SettingActivity" />
<activity android:name="activity.TemplateActivity" />
<activity android:name="activity.KontakListActivity" />
<activity android:name="activity.PencarianActivity" />
<activity android:name="activity.KontakFavoritActivity" />
谢谢。
【讨论】:
以上是关于Eclipse - 不幸的是应用程序已停止 - ClassNotFoundException:在路径上找不到类的主要内容,如果未能解决你的问题,请参考以下文章
Eclipse - 不幸的是应用程序已停止 - ClassNotFoundException:在路径上找不到类