2013-10-15 146 views
0

這些是我的兩個類和我的清單。我得到了一個ClassNotFoundException。我還包括我的日誌貓。Android ClassNotFound異常

我的第一類:

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

您是否嘗試過清潔和重建? –

+0

你的包名是com.m.mech包; – Raghunandan

回答

2

這條線在你的清單不符合您的主要活動中你的包/類名:

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

將其更改爲

android:name="com.m.mech.MainActivity" 
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" > 
.... 
0

您的主要活動是在包com.m.mech但在你的manifest文件你把com.parse.mech.MainActivity爲起點

0

whow .. 如果你的包名是正確的,只需清理項目並重新導出。 它對我來說很有用!

+0

這對我有用。謝謝! :) –

-1

瞭解Android Studio
即使在清單文件更改包名不爲你工作後,只要嘗試無效緩存和重新加載項目。它爲我工作。

所有文件對我來說都是正確的,但仍然有這個錯誤。我剛剛創建使用默認模板類Android Studio中

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

對於Eclipse
清潔工程和重新加載它。