简体   繁体   English

Android:找不到类异常

[英]Android: Class not found exception

I've looked all similar questions and none of the solutions presented did solve my problem. 我看过所有类似的问题,但所提供的解决方案都不能解决我的问题。

When my application is launcher I am presented with the following: 当我的应用程序是启动器时,将显示以下内容:

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

My class that extends Application 我的班级扩展了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();
    }
`

UPDATE: Seems like the problem is not in the libraries or any particular class, even if I remove the SocialGeek extends Application I got the same exception in my MainActivity . 更新:似乎问题不在库或任何特定类中,即使我删除了SocialGeek extends Application我在MainActivity也遇到了相同的异常。 I removed all my dependencies, deleted even eclipse and re-installed but the problem remains... 我删除了所有依赖项,甚至删除了Eclipse并重新安装,但问题仍然存在...

Do you have package com.triandria.socialgeek; 您是否有package com.triandria.socialgeek; on the first line in java file? 在java文件的第一行?

Took me a while to figure this out. 花了我一段时间来解决这个问题。

I had to right click the project -> build path-> configure build path -> Source tab 我必须右键单击project -> build path-> configure build path -> Source选项卡

and un-tick the Allow output folders for source folders . 取消勾选 Allow output folders for source folders

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM