静态SharedPreference NoClassDefFoundError

时间:2015-03-06 21:23:10

标签: java jdbc sharedpreferences

我正在尝试使用共享首选项在jdbc字符串中填充dbname。我得到的错误是

03-06 15:46:25.941: E/AndroidRuntime(3605): Caused by: java.lang.NoClassDefFoundError: com/vr/activities/DatabaseConnection

JDBC连接完美无缺,但无法使其与共享首选项一起使用。

这是我的代码:

公共类DatabaseConnection扩展了Activity {

public static Context dbContext;
private static Connection connection = null;
private static DatabaseConnection instance = null;
private final static String DRIVER = "org.postgresql.Driver";

public static class pro

{
    public static String dbname() {
        PreferenceHelper preferenceHelper = new PreferenceHelper(dbContext);
        return preferenceHelper.getDBname();
    }
}
 static String dbname=pro.dbname();

private final static String DATABASE = dbname;


    //constructor
    public DatabaseConnection() {
    super();
    }

Android Manifest.xml

  <activity
        android:name=".activities.DatabaseConnection"
        android:label="@string/database_connection"
        android:parentActivityName=".activities.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".activities.MainActivity" />
    </activity>

PreferenceHelper是我的SharedPreferences帮助文件,它适用于我在应用程序中的一些活动。 preferenceHelper.getDBname()也在另一个活动中调用,它的工作正常,所以我知道这不是问题。 如果我使用硬编码的静态字符串,它可以与jdbc驱动程序

一起使用
private final static String DATABASE = "mydatabase";

这是堆栈跟踪:

03-06 16:39:59.910: E/AndroidRuntime(1854): FATAL EXCEPTION: AsyncTask #1
03-06 16:39:59.910: E/AndroidRuntime(1854): Process: com.vr PID: 1854
03-06 16:39:59.910: E/AndroidRuntime(1854): java.lang.RuntimeException: An error occured while executing doInBackground()
03-06 16:39:59.910: E/AndroidRuntime(1854):     at android.os.AsyncTask$3.done(AsyncTask.java:300)
03-06 16:39:59.910: E/AndroidRuntime(1854):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
03-06 16:39:59.910: E/AndroidRuntime(1854):     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
03-06 16:39:59.910: E/AndroidRuntime(1854):     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
03-06 16:39:59.910: E/AndroidRuntime(1854):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
03-06 16:39:59.910: E/AndroidRuntime(1854):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-06 16:39:59.910: E/AndroidRuntime(1854):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-06 16:39:59.910: E/AndroidRuntime(1854):     at java.lang.Thread.run(Thread.java:841)
03-06 16:39:59.910: E/AndroidRuntime(1854): Caused by: java.lang.NoClassDefFoundError: com/vr/activities/DatabaseConnection
03-06 16:39:59.910: E/AndroidRuntime(1854):     at com.vr.activities.MaintenanceActivity$1$2$1LongOperation.doInBackground(MaintenanceActivity.java:91)
03-06 16:39:59.910: E/AndroidRuntime(1854):     at com.vr.activities.MaintenanceActivity$1$2$1LongOperation.doInBackground(MaintenanceActivity.java:72)
03-06 16:39:59.910: E/AndroidRuntime(1854):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-06 16:39:59.910: E/AndroidRuntime(1854):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-06 16:39:59.910: E/AndroidRuntime(1854):     ... 4 more
03-06 16:39:59.920: W/ActivityManager(1274):   Force finishing activity com.vr/.activities.MaintenanceActivity

0 个答案:

没有答案