[英]Android: Class not found exception
我看過所有類似的問題,但所提供的解決方案都不能解決我的問題。
當我的應用程序是啟動器時,將顯示以下內容:
12-23 19:27:39.207: E/Trace(1884): error opening trace file: No such file or directory (2)
12-23 19:27:39.217: D/AndroidRuntime(1884): Shutting down VM
12-23 19:27:39.217: W/dalvikvm(1884): threadid=1: thread exiting with uncaught exception (group=0x416ae300)
12-23 19:27:39.217: E/AndroidRuntime(1884): FATAL EXCEPTION: main
12-23 19:27:39.217: E/AndroidRuntime(1884): java.lang.RuntimeException: Unable to instantiate application com.triandria.socialgeek.SocialGeek: java.lang.ClassNotFoundException: com.triandria.socialgeek.SocialGeek
12-23 19:27:39.217: E/AndroidRuntime(1884): at android.app.LoadedApk.makeApplication(LoadedApk.java:501)
12-23 19:27:39.217: E/AndroidRuntime(1884): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4124)
12-23 19:27:39.217: E/AndroidRuntime(1884): at android.app.ActivityThread.access$1300(ActivityThread.java:130)
12-23 19:27:39.217: E/AndroidRuntime(1884): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
12-23 19:27:39.217: E/AndroidRuntime(1884): at android.os.Handler.dispatchMessage(Handler.java:99)
12-23 19:27:39.217: E/AndroidRuntime(1884): at android.os.Looper.loop(Looper.java:137)
12-23 19:27:39.217: E/AndroidRuntime(1884): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-23 19:27:39.217: E/AndroidRuntime(1884): at java.lang.reflect.Method.invokeNative(Native Method)
12-23 19:27:39.217: E/AndroidRuntime(1884): at java.lang.reflect.Method.invoke(Method.java:511)
12-23 19:27:39.217: E/AndroidRuntime(1884): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-23 19:27:39.217: E/AndroidRuntime(1884): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-23 19:27:39.217: E/AndroidRuntime(1884): at dalvik.system.NativeStart.main(Native Method)
12-23 19:27:39.217: E/AndroidRuntime(1884): Caused by: java.lang.ClassNotFoundException: com.triandria.socialgeek.SocialGeek
12-23 19:27:39.217: E/AndroidRuntime(1884): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-23 19:27:39.217: E/AndroidRuntime(1884): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-23 19:27:39.217: E/AndroidRuntime(1884): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-23 19:27:39.217: E/AndroidRuntime(1884): at android.app.Instrumentation.newApplication(Instrumentation.java:967)
12-23 19:27:39.217: E/AndroidRuntime(1884): at android.app.LoadedApk.makeApplication(LoadedApk.java:496)
12-23 19:27:39.217: E/AndroidRuntime(1884): ... 11 more
我的班級擴展了Application
public class SocialGeek extends Application {
private static final String TAG = "Social Geek";
private static Context context;
public static SharedPreferences sharedPreferences;
private static SQLiteDatabase savedProfilesDatabase;
private static DatabaseHelper savedProfilesDatabaseHelper;
private static int width, height;
private static boolean REMOTE_PROFILE_CREATED = false;
private static Location CURRENT_USER_LOCATION;
@Override
public void onCreate() {
super.onCreate();
SocialGeek.context = getApplicationContext();
sharedPreferences = getSharedPreferences(Activity_my_profile.FILENAME,
MODE_PRIVATE);
calculateScreenDimensions();
//TODO if no memory card is present we get errors
savedProfilesDatabaseHelper = new DatabaseHelper(context);
ContentValues contentValues = new ContentValues();
contentValues.put(
SavedProfilesDatabaseScheme.SavedProfilesTable.PROFILE_NAME,
"Dobrovnik");
contentValues
.put(SavedProfilesDatabaseScheme.SavedProfilesTable.PROFILE_DESCRIPTION,
" Stolischnaya University");
savedProfilesDatabase = savedProfilesDatabaseHelper
.getWritableDatabase();// only for mock data
// int rowsDeleted =
// savedProfilesDatabase.delete(SavedProfilesTable.TABLE_NAME, null,
// null);// duplicate values? mock
// Log.d(TAG, "Rows deleted: "+rowsDeleted);
Long newRowId = savedProfilesDatabase.insert(
SavedProfilesTable.TABLE_NAME, null, contentValues);
Log.d(TAG, ("Inserted row: " + newRowId.toString()));
savedProfilesDatabase.close();
}
`
更新:似乎問題不在庫或任何特定類中,即使我刪除了SocialGeek extends Application
我在MainActivity
也遇到了相同的異常。 我刪除了所有依賴項,甚至刪除了Eclipse並重新安裝,但問題仍然存在...
您是否有package com.triandria.socialgeek;
在java文件的第一行?
花了我一段時間來解決這個問題。
我必須右鍵單擊project -> build path-> configure build path -> Source
選項卡
並取消勾選 Allow output folders for source folders
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.