0

这是我的两个班级和我的清单。我有一个ClassNotFoundException. 我还包括了我的日志猫。

我的第一堂课:

  package com.m.mech;

    import com.parse.Parse;
    import com.parse.ParseACL;

    import com.parse.ParseUser;

    import android.app.Application;

    public class ParsePro extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        // Add your initialization code here
        Parse.initialize(this,"tadjgdfghdfgdfdfcfgdfcr",      "QlwkikEQCXZ8cW9ghjwbFpXjAaWEr5Js6H2Cud5");


        PushService.setDefaultPushCallback(this, MainActivity.class);
        ParseInstallation.getCurrentInstallation().saveInBackground();
        ParseUser.enableAutomaticUser();
        ParseACL defaultACL = new ParseACL();

        // If you would like all objects to be private by default, remove this line.
        defaultACL.setPublicReadAccess(true);

        ParseACL.setDefaultACL(defaultACL, true);
    }

}

我的第二堂课:

package com.m.mech;

import com.m.mech.R;
import android.app.Activity;
import android.os.Bundle;

import com.parse.ParseAnalytics;

 public class MainActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ParseAnalytics.trackAppOpened(getIntent());
}
}

我的清单:

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

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />

    <application

    android:name="com.m.mech.ParsePro"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name="com.parse.mech.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <service android:name="com.parse.PushService" />

    <receiver android:name="com.parse.ParseBroadcastReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>
    </application>
    </manifest>

我的日志猫:

10-15 14:59:36.168: E/AndroidRuntime(1114): FATAL EXCEPTION: main
10-15 14:59:36.168: E/AndroidRuntime(1114): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.m.mech/com.parse.mech.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.parse.mech.MainActivity" on path: /data/app/com.m.mech-2.apk
10-15 14:59:36.168: E/AndroidRuntime(1114):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at android.os.Looper.loop(Looper.java:137)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at android.app.ActivityThread.main(ActivityThread.java:5039)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at java.lang.reflect.Method.invokeNative(Native Method)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at java.lang.reflect.Method.invoke(Method.java:511)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at dalvik.system.NativeStart.main(Native Method)
10-15 14:59:36.168: E/AndroidRuntime(1114): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.parse.mech.MainActivity" on path: /data/app/com.m.mech-2.apk
10-15 14:59:36.168: E/AndroidRuntime(1114):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
10-15 14:59:36.168: E/AndroidRuntime(1114):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
10-15 14:59:36.168: E/AndroidRuntime(1114):     ... 11 more
10-15 14:59:47.998: E/Trace(1137): error opening trace file: No such file or directory (2)

为什么我会得到这个ClassNotFoundException

4

6 回答 6

2

您的清单中的这一行与您的主要活动的包/类名不匹配:

android:name="com.parse.mech.MainActivity"

将其更改为

android:name="com.m.mech.MainActivity"
于 2013-10-15T15:12:40.243 回答
1

使用正确的包名称来注册服务和活动,AndroidManifest.xml因为包名称是com.m.mech但您当前com.parse用于注册。

....
<activity
    android:name="com.m.mech.MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

<service android:name="com.m.mech.PushService" />

<receiver android:name="com.m.mech.ParseBroadcastReceiver" >
 ....
于 2013-10-15T15:12:06.457 回答
0

您的主要活动在包中,com.m.mech但在您的清单文件中com.parse.mech.MainActivity作为起点

于 2013-10-15T15:12:17.817 回答
0

哇..如果您的包名正确,只需清理项目并再次导出..它对我有用!

于 2014-09-15T04:11:35.120 回答
0

对于 Android Studio
即使在清单文件中更改包名称后对您不起作用,也只需尝试使缓存无效并重新加载项目即可。它对我有用。

所有文件对我来说都是正确的,但仍然存在此错误。我刚刚在 Android Studio 中使用默认模板创建了类

File > Invalidate Caches/Restart > Invalidate Cache and Restart (DIalog box)

对于 Eclipse
清理项目并重新加载它。

于 2015-01-12T14:08:40.183 回答
0

就我而言,问题是主题!

于 2018-04-20T14:53:00.670 回答