这是我的两个班级和我的清单。我得到了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>
我的LogCat:
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
?
答案 0 :(得分:2)
清单中的这一行与您的主要活动的包/类名不符:
android:name="com.parse.mech.MainActivity"
将其更改为
android:name="com.m.mech.MainActivity"
答案 1 :(得分: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" >
....
答案 2 :(得分:0)
您的主要活动位于包com.m.mech
,但在您的清单文件中,您将com.parse.mech.MainActivity
作为起点
答案 3 :(得分:0)
whow .. 如果您的包名称正确,只需清理项目并再次导出它。 这对我有用!
答案 4 :(得分:0)
就我而言,问题是主题!
答案 5 :(得分:-1)
适用于Android Studio
即使在清单文件中更改软件包名称后对您不起作用,也只是尝试使缓存无效并重新加载项目。它对我有用。
所有文件对我来说都是正确的,但仍然存在此错误。我刚刚在Android Studio中使用默认模板创建了类
File > Invalidate Caches/Restart > Invalidate Cache and Restart (DIalog box)
对于Eclipse
清理项目并重新加载。