引起:java.lang.ClassNotFoundException:没有在路径上找到类

时间:2014-03-26 12:19:19

标签: java android logcat splash-screen

启动我的应用程序后,模拟器告诉我,不幸的是它已经停止了。我之前遇到了同样的错误,然后我修复了它,但是在添加启动活动之后我又遇到了这个问题。

03-24 15:14:21.180: E/AndroidRuntime(857): FATAL EXCEPTION: main
03-24 15:14:21.180: E/AndroidRuntime(857): Process: com.gosha.bux, PID: 857
03-24 15:14:21.180: E/AndroidRuntime(857): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.gosha.bux/com.gosha.bux.perv}: java.lang.ClassNotFoundException: Didn't find class "com.gosha.bux.perv" on path: DexPathList[[zip file "/data/app/com.gosha.bux-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.gosha.bux-2, /system/lib]]
03-24 15:14:21.180: E/AndroidRuntime(857):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
03-24 15:14:21.180: E/AndroidRuntime(857):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-24 15:14:21.180: E/AndroidRuntime(857):  at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-24 15:14:21.180: E/AndroidRuntime(857):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-24 15:14:21.180: E/AndroidRuntime(857):  at android.os.Handler.dispatchMessage(Handler.java:102)
03-24 15:14:21.180: E/AndroidRuntime(857):  at android.os.Looper.loop(Looper.java:136)
03-24 15:14:21.180: E/AndroidRuntime(857):  at android.app.ActivityThread.main(ActivityThread.java:5017)
03-24 15:14:21.180: E/AndroidRuntime(857):  at java.lang.reflect.Method.invokeNative(Native Method)
03-24 15:14:21.180: E/AndroidRuntime(857):  at java.lang.reflect.Method.invoke(Method.java:515)
03-24 15:14:21.180: E/AndroidRuntime(857):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-24 15:14:21.180: E/AndroidRuntime(857):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-24 15:14:21.180: E/AndroidRuntime(857):  at dalvik.system.NativeStart.main(Native Method)
03-24 15:14:21.180: E/AndroidRuntime(857): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.gosha.bux.perv" on path: DexPathList[[zip file "/data/app/com.gosha.bux-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.gosha.bux-2, /system/lib]]
03-24 15:14:21.180: E/AndroidRuntime(857):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-24 15:14:21.180: E/AndroidRuntime(857):  at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
03-24 15:14:21.180: E/AndroidRuntime(857):  at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
03-24 15:14:21.180: E/AndroidRuntime(857):  at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
03-24 15:14:21.180: E/AndroidRuntime(857):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
03-24 15:14:21.180: E/AndroidRuntime(857):  ... 11 more
03-24 15:14:43.061: I/Process(857): Sending signal. PID: 857 SIG: 9

清单

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" 
    android:debuggable="true"
    >
    <activity
        android:name="com.gosha.bux.perv"
        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="com.gosha.bux.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.gosha.bux.MAINACTIVITY" />

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

启动活动

    public class perv extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(com.gosha.bux.R.layout.pervy);
        Thread timer = new Thread(){
            public void run(){
                try{
                    sleep(5000);
                }
            catch (InterruptedException e){
                e.printStackTrace();
            }
                finally {
                    Intent openMainActivity = new Intent("com.gosha.bux.MAINACTIVITY");
                    startActivity(openMainActivity);
                }
            }

        };
    }

    }

4 个答案:

答案 0 :(得分:1)

只需这样做

Intent i = new Intent(getapplicationcontext(),
                            TARGET_Activity.class);
                    startActivity(i);

并在清单

<activity
            android:name="com.your.packagename.TARGET_Activity"

            android:screenOrientation="portrait" >
        </activity>

答案 1 :(得分:1)

在你的依赖编译中:

'com.android.support:multidex:1.0.0'

并设置multiDexEnabled true

YourApplicationextends MultiDexApplication

添加:

@Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

最后在AndroidManifest声明:android:name=".MyApplication"

答案 2 :(得分:0)

  Intent openMainActivity = new Intent("com.gosha.bux.MAINACTIVITY");
                startActivity(openMainActivity);

是错误的,而是使用:

Intent openMainActivity = new Intent(this, YourMainActivity.class);

答案 3 :(得分:0)

在Public class perv中你写了这个:

的setContentView(com.gosha.bux.R.layout.pervy);

你写了pervy而不是perv,这可能会导致这个错误