神秘持久的ClassNotFoundException(主要活动)

时间:2012-01-30 23:06:55

标签: java android android-manifest classnotfoundexception

我一直在阅读其他人遇到过这个问题的解决方案,而且大多数答案都表明它是清单的问题,但我看不出有什么问题。我看起来很准确但我一直在运行时ClassNotFoundException。

SongbirdActivity.java:

package com.songbirdapp.songbird;

import android.app.Activity;
import android.os.Bundle;

public class SongbirdActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.songbirdapp.songbird"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:targetSdkVersion="15" />
    <uses-sdk android:minSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".SongbirdActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>


</manifest>

有人能在这里看到问题吗?

LOGCAT输出:

01-30 15:28:21.622: D/AndroidRuntime(1315): Shutting down VM
01-30 15:28:21.692: W/dalvikvm(1315): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
01-30 15:28:21.712: E/AndroidRuntime(1315): FATAL EXCEPTION: main
01-30 15:28:21.712: E/AndroidRuntime(1315): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.songbirdapp.songbird/com.songbirdapp.songbird.SongbirdActivity}: java.lang.ClassNotFoundException: com.songbirdapp.songbird.SongbirdActivity
01-30 15:28:21.712: E/AndroidRuntime(1315):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at android.os.Looper.loop(Looper.java:137)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at android.app.ActivityThread.main(ActivityThread.java:4424)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at java.lang.reflect.Method.invokeNative(Native Method)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at java.lang.reflect.Method.invoke(Method.java:511)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at dalvik.system.NativeStart.main(Native Method)
01-30 15:28:21.712: E/AndroidRuntime(1315): Caused by: java.lang.ClassNotFoundException: com.songbirdapp.songbird.SongbirdActivity
01-30 15:28:21.712: E/AndroidRuntime(1315):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
01-30 15:28:21.712: E/AndroidRuntime(1315):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
01-30 15:28:21.712: E/AndroidRuntime(1315):     ... 11 more

2 个答案:

答案 0 :(得分:1)

这个问题违背了所有回答这个问题的尝试。我要修改项目并重新开始,然后只需复制并粘贴旧代码。

答案 1 :(得分:0)

我看到了同样的行为,最终为我解决的是确保当我去导出apk时,在该位置没有同名的现有apk文件。当有(例如,在一个小的改变之后导出)时,apk通常最终会变得明显更小(~600k vs~720k),并且一旦启动,通常会导致此CallNotFoundException。

一旦我确定在导出之前删除现有的APK,我就停止了这个讨厌的问题。

也许这会帮助别人。

Windows 7上的Eclipse 4.2.0 ADT 21.0.0