无法打开数据库/无法将(数据库)的区域设置更改为“en_US”

2023-12-06

我已阅读解决方案无法将数据库“/data/data/my.easymedi.controller/databases/EasyMediInfo.db”的区域设置更改为“en_US”但这对我没有帮助。我仍然有同样的错误。

这些是我的DBHelper班级。你能调查一下并帮助我吗?

package com.example.mgr;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Date;
import java.util.ArrayList;


import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper{

    //The Android's default system path of your application database.
    private static String DB_PATH = "/data/data/com.example.mgr/databases/";

    private static String DB_NAME = "Mgr.Test.db";

    private SQLiteDatabase myDataBase; 

    private final Context myContext;

    public static final String KEY_ROWID = "_id";

    public static final String KEY_DATE = "DataWstawiena";

    public static final String KEY_TRESC = "Tresc";

    public static final String DATABASE_NAME = "Mgr.Test";

    public static final String DATABASE_TABLE = "InformacjeZDziekanatu";
    private static int DATABASE_VERSION = 18;
    /**
     * Constructor
     * Takes and keeps a reference of the passed context in order to access to the application assets and resources.
     * @param context
     */
    public DBHelper(Context context) {

        super(context, DB_NAME, null, DATABASE_VERSION);
        System.out.println("------Odpalam DBHelpera---wolane z konstruktora----");
        this.myContext = context;
    }   

  /**
     * Creates a empty database on the system and rewrites it with your own database.
     * */
    public void createDataBase() throws IOException{

        boolean dbExist = checkDataBase();
        System.out.println("----Baza istnieje: " + dbExist + "-----");

        if(dbExist){
            System.out.println("----Baza istnieje!");
            this.getReadableDatabase();
            System.out.println("----Baza istnieje! znow");
            //do nothing - database already exist
        }
        dbExist = checkDataBase();
        if(!dbExist){
            System.out.println("----Baza nie istnieje");

            //By calling this method and empty database will be created into the default system path
               //of your application so we are gonna be able to overwrite that database with our database.
            this.getReadableDatabase();

            try {
                System.out.println("Bede kopiowal");
                copyDataBase();

            } catch (IOException e) {

                throw new Error("Error copying database");

            }
        }

    }

    /**
     * Check if the database already exist to avoid re-copying the file each time you open the application.
     * @return true if it exists, false if it doesn't
     */
    private boolean checkDataBase(){

        SQLiteDatabase checkDB = null;
        System.out.println("----Baza istnieje w checkDB!");
        try{
            String myPath = DB_PATH + DB_NAME;
            checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS|SQLiteDatabase.OPEN_READONLY);
            System.out.println("Bazka otwarta!");

        }catch(SQLiteException e){

            System.out.println("database does't exist yet");

        }

        if(checkDB != null){
            System.out.println("Zamykam baze");

            checkDB.close();

        }

        return checkDB != null ? true : false;
    }

    /**
     * Copies your database from your local assets-folder to the just created empty database in the
     * system folder, from where it can be accessed and handled.
     * This is done by transfering bytestream.
     * */
    private void copyDataBase() throws IOException{

        //Open your local db as the input stream
        InputStream myInput = myContext.getAssets().open(DB_NAME);

        // Path to the just created empty db
        String outFileName = DB_PATH + DB_NAME;

        //Open the empty db as the output stream
        OutputStream myOutput = new FileOutputStream(outFileName);

        //transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer))>0){
            myOutput.write(buffer, 0, length);
        }

        //Close the streams
        myOutput.flush();
        myOutput.close();
        myInput.close();

    }

    public SQLiteDatabase openDataBase() throws SQLException{

        String myPath = DB_PATH + DB_NAME;
        myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS|SQLiteDatabase.OPEN_READONLY);
        return myDataBase;
    }

    @Override
    public synchronized void close() {

            if(myDataBase != null)
                myDataBase.close();

            super.close();

    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        try {
            copyDataBase();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(" ----Jestem w mtodzie onUpgrade------");
        //DATABASE_VERSION++;

    }

    /**
    * Wykonuje zapytanie SQL
    * @param query - zapytanie SQL
    * @return zwraca Stringa z rezultatem
    */
    public String executeQuery(String query){
    String result = "";
    Cursor cursor = myDataBase.rawQuery(query, null);
    String dataWs ="Data Wstawienia ";
    String tresc = "Tresc";
    result = dataWs + tresc + "\n";
    if(cursor.moveToFirst())
    {
    do
    {
    result +=  cursor.getString(1) +" "+ cursor.getString(3)+"\n";
    }while(cursor.moveToNext());
    }

    return result;
    }

    /**
    * Wykonuje zapytanie SQL i zwraca tablice
    * @param query - zapytanie SQL
    * @return zwraca tablie Stringa z rezultatem
    */
    public ArrayList<String> executeQueryTab(String query){
    ArrayList<String> result = new ArrayList<String>();
    Cursor cursor = myDataBase.rawQuery(query, null);
    String dataWs ="Data Wstawienia ";
    String tresc = "Tresc";
    result.add(dataWs + tresc);
    if(cursor.moveToFirst())
    {
    do
    {
    result.add(cursor.getString(1) +" "+ cursor.getString(3));
    }while(cursor.moveToNext());
    }

    return result;
    }


        // Add your public helper methods to access and get content from the database.
       // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy
       // to you to create adapters for your views.

}

它以前工作得很好,但我对数据库进行了一些升级,然后它停止工作。我想这是这个错误的根源,但我不确定。

提前致谢!

根据您的要求:

我在我的方法中调用了 createDataBase 方法主要活动类,如下所示:

package com.example.mgr;

import java.io.IOException;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {

    SharedPreferences preferences;
    TextView tv;
    Adapter adapter;
    SQLiteDatabase as;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button infDlaStudButton = (Button) findViewById(R.id.infDlaStud);
        Button infDlaKandButton = (Button) findViewById(R.id.infDlaKand);
        preferences = PreferenceManager.getDefaultSharedPreferences(this);
        DBHelper myDbHelper = new DBHelper(this);
        infDlaStudButton.setOnClickListener(this);
        infDlaKandButton.setOnClickListener(this);

        infDlaKandButton.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                ble();

            }

        });

        infDlaStudButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                ble();
            }
        });

        try {
            myDbHelper.createDataBase();
            System.out.println("Stworzyłam bazę danych");

        } catch (IOException ioe) {

            throw new Error("nie moge to create database");

        }
        System.out.println("bede otwierdal baze danych w glowej metodzie");

        myDbHelper.openDataBase();

    }

    void ble() {
        Intent intent = new Intent();
        intent.setClass(MainActivity.this, SecondActivity.class);
        startActivity(intent);
    }

    @Override
    public void onClick(View arg0) {
        Toast.makeText(this, "ble", Toast.LENGTH_LONG).show();
        // TODO Auto-generated method stub

    }

}

是的android_元数据表存在于数据库中并且具有 'en_US' value.

我创建了新的、非常简单的数据库德热沃数据库。当这个表只有2个表时:andoid_元数据和另一个(Przyjeci)然后一切正常!但后来我添加了新表并尝试进行升级,但出现了相同的错误。

有我的logs(来自这个新数据库):

12-04 19:58:41.959: E/SQLiteLog(2293): (11) database corruption at line 50741 of [00bb9c9ce4]
12-04 19:58:41.959: E/SQLiteLog(2293): (11) database corruption at line 50780 of [00bb9c9ce4]
12-04 19:58:41.969: E/SQLiteLog(2293): (11) statement aborts at 16: [SELECT locale FROM android_metadata UNION SELECT NULL ORDER BY locale DESC LIMIT 1] 
12-04 19:58:42.056: E/SQLiteDatabase(2293): Failed to open database '/data/data/com.example.mgr/databases/Drzewo.db'.
12-04 19:58:42.056: E/SQLiteDatabase(2293): android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/com.example.mgr/databases/Drzewo.db' to 'en_US'.
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:386)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:218)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:854)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:229)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at com.example.mgr.DBHelper.createDataBase(DBHelper.java:53)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at com.example.mgr.MainActivity.onCreate(MainActivity.java:73)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.app.Activity.performCreate(Activity.java:5104)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.os.Looper.loop(Looper.java:137)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.app.ActivityThread.main(ActivityThread.java:5041)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at java.lang.reflect.Method.invokeNative(Native Method)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at java.lang.reflect.Method.invoke(Method.java:511)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at dalvik.system.NativeStart.main(Native Method)
12-04 19:58:42.056: E/SQLiteDatabase(2293): Caused by: android.database.sqlite.SQLiteDatabaseCorruptException: database disk image is malformed (code 11)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteConnection.nativeExecuteForString(Native Method)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:634)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:367)
12-04 19:58:42.056: E/SQLiteDatabase(2293):     ... 28 more
12-04 19:58:42.219: E/SQLiteOpenHelper(2293): Couldn't open Drzewo.db for writing (will try read-only):
12-04 19:58:42.219: E/SQLiteOpenHelper(2293): android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/com.example.mgr/databases/Drzewo.db' to 'en_US'.
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:386)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:218)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:854)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:229)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at com.example.mgr.DBHelper.createDataBase(DBHelper.java:53)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at com.example.mgr.MainActivity.onCreate(MainActivity.java:73)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.app.Activity.performCreate(Activity.java:5104)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.os.Handler.dispatchMessage(Handler.java:99)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.os.Looper.loop(Looper.java:137)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.app.ActivityThread.main(ActivityThread.java:5041)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at java.lang.reflect.Method.invokeNative(Native Method)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at java.lang.reflect.Method.invoke(Method.java:511)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at dalvik.system.NativeStart.main(Native Method)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293): Caused by: android.database.sqlite.SQLiteDatabaseCorruptException: database disk image is malformed (code 11)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteConnection.nativeExecuteForString(Native Method)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:634)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:367)
12-04 19:58:42.219: E/SQLiteOpenHelper(2293):   ... 28 more
12-04 19:58:42.259: D/AndroidRuntime(2293): Shutting down VM
12-04 19:58:42.280: W/dalvikvm(2293): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
12-04 19:58:42.359: E/AndroidRuntime(2293): FATAL EXCEPTION: main
12-04 19:58:42.359: E/AndroidRuntime(2293): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mgr/com.example.mgr.MainActivity}: android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 5 to 6: Drzewo.db
12-04 19:58:42.359: E/AndroidRuntime(2293):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at android.os.Looper.loop(Looper.java:137)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at android.app.ActivityThread.main(ActivityThread.java:5041)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at java.lang.reflect.Method.invokeNative(Native Method)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at java.lang.reflect.Method.invoke(Method.java:511)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at dalvik.system.NativeStart.main(Native Method)
12-04 19:58:42.359: E/AndroidRuntime(2293): Caused by: android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 5 to 6: Drzewo.db
12-04 19:58:42.359: E/AndroidRuntime(2293):     at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:245)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at com.example.mgr.DBHelper.createDataBase(DBHelper.java:53)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at com.example.mgr.MainActivity.onCreate(MainActivity.java:73)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at android.app.Activity.performCreate(Activity.java:5104)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-04 19:58:42.359: E/AndroidRuntime(2293):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-04 19:58:42.359: E/AndroidRuntime(2293):     ... 11 more

我致力于eclipse juno + 安卓4.2.2


我无法将所有这些代码都放在注释中,所以请尝试这些: 请记住,我不会添加所有样板......好吗?

更改 checkDb 方法:

private boolean checkDataBase(){
     File dbFile = new File( DATABASE_PATH, DATABASE_NAME );
     return dbFile.exists();
}

更改createDb方法:

public void createDataBase() {
    if(checkDb()){
        //do nothing
    } else {
        copyDatabase();
    }
}

更改 copyDatabase() 方法:

private void copyDataBase(){
      getReadableDatabase();

      //add the rest of your current implementation

}

将构造函数的可访问性更改为私有并添加以下方法:

private DBHelper mInstance = null;
public static DBHelper getInstance(Context context) {
   if(mInstance == null)
        mInstance = new DBHelper(context)
   return mInstance;
}
//remove the old openDatabase method
public SQLiteDatabase openDatabase() {
   return getReadableDatabase(); //or you can use getWritableDatabase();
}

此外,我注意到您发布的代码中的数据库版本是 18,而您发布的日志中显示的是 5 或 6?可以贴一下最新的日志吗...

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法打开数据库/无法将(数据库)的区域设置更改为“en_US” 的相关文章

  • 如何在首次运行时填充大型 SQLite 数据库

    我正在开发一个基于 SQLite 数据库的字典应用程序 该数据库包含超过 300 000 行 问题在于 最终形式的数据库文件由全文索引表组成 并且重量远远超过150Mb 我通过创建无内容的 fts4 表设法将 db 文件大小降至最低 数据库
  • 直接在布局 xml 中填充微调器

    是否可以在布局 xml 中直接填充 Spinner 的选项 这一页 http developer android com guide tutorials views hello spinner html建议我应该使用 ArrayAdapte
  • RecyclerView onItemClickListener 不工作

    我正在研究回收视图并尝试对 recyclerview 的每个项目使用点击侦听器界面 这是我的活动课程 public class LegacyHomeActivity extends ActivityBaseDrawer private Li
  • Android:iOS UIActionSheet 等效项

    我正在转换一个 iOS 应用程序 并且需要实现从 iOS 到 Android 的 UIActionSheet 的等效项 什么 UI 元素最能模仿这一点 我的目标是 Android 2 2 及更高版本 您将使用 AlertDialog 或 D
  • 如何在使用 Web 服务时获取会话对象?

    如何在使用 Web 服务时获取会话对象 服务在两个程序之间调用 如何在使用 Web 服务时获取用户会话对象 不可能使用请求对象获取会话 因为当我们谈论服务时不会有请求或响应 如果您正在与JAX WS https jax ws dev jav
  • 使用 TestRestTemplate 和 MockRestServiceServer 时,解析异常而不是实体列表不起作用

    我有一个简单的控制器 CODE https github com joergi tryouts blob main kotlin mockrestserver src main kotlin io joergi kotlinmockrest
  • Java - 在特定日期执行方法[关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我需要在每年的特定日期执行一个方法 我该如何在java中执行此操作 Thanks Chris 按优先顺序排列 The Quartz htt
  • 使用电子邮件、用户名和密码进行 Firebase 身份验证

    我想知道是否可以使用电子邮件和用户 ID 密码登录 我有一个项目 我希望用户添加一个唯一的号码 实际上是我们公司提供的工作识别号码 以便能够签名参与该计划的人员将继续留在公司就业 即使电子邮件和密码正确但用户 ID 错误 我也需要 fire
  • Android 检测片段何时分离

    我可以轻松检测到Fragments附于Activity via Activity onAttachFragment 但我怎样才能检测到Activity那一些Fragment脱离活动了吗 没有Activity onDetachFragment
  • 在 Repository 类中观察 Forever 是一个好习惯吗?数据库+网络分页列表

    我正在按照架构指南构建应用程序 实现了房间数据库缓存 网络 需要从单独的实体获取最新页码 我的型号 Entity tableName top rated movie page public class Top Rated Movies Pa
  • 如何执行graph-api Facebook Android SDK来上传照片并标记人物?

    如何执行graph api Facebook Android SDK来上传照片并标记人物 在网络上 对于 Android 版 facebook sdk 有很多混淆 我的第一个方法 Bitmap img bitmap if img null
  • 在java中的super调用之前创建一个对象

    考虑到简单的java代码是行不通的 public class Bar extends AbstractBar private final Foo foo new Foo bar public Bar super foo 我需要在之前创建一个
  • Java 有现成的时钟同步解决方案吗?

    我们有一个大型的高性能软件系统 它由多个交互的 Java 进程 不是 EJB 组成 每个进程可以在同一台机器上 也可以在不同的机器上 某些事件在一个进程中生成 然后以不同的方式传播到其他进程以进行进一步处理等 出于基准测试的目的 我们需要创
  • 我们还需要迭代器设计模式吗? [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • Eclipse 包资源管理器缩放?

    我发现将 Eclipse 配置为完全符合您的要求是一项艰巨的工作 因此我不打算自己尝试这样做 我想 缩小 包浏览器侧边栏 你看 我喜欢只在屏幕上显示我的代码 并为项目中的文件显示一小部分 但是 由于这个原因 我永远无法看到当前所在的文件或包
  • javaFX,抛出 NullPointerException,位置是必需的

    我看过其他答案 但没有任何帮助我 抱歉 GUI新手只知道swing的基础知识 这是主课 package application import javafx application Application import javafx fxml
  • 设置滚动条粗细

    有没有办法调整滚动条的粗细JScrollPane 默认值有点笨拙 一个快速但又肮脏的解决方案是将宽度 高度明确设置为例如10 像素通过 jScrollPane getVerticalScrollBar setPreferredSize ne
  • 数组所有可能的组合

    我有一个字符串数组 ted williams golden voice radio 我希望这些关键字的所有可能组合采用以下形式 ted williams golden voice radio ted williams ted golden
  • 如果 windowTranslucentStatus 为 false,则不会调用键盘的 onApplyWindowInsets

    正如标题所说 我有一个Activity我想在其上处理键盘的插入 底部有一个视图 不应该推上去 但其余的观点应该被推高 我可以使用很好地处理插图onApplyWindowInsets IF windowTranslucentStatus设置为
  • 使用 Jsoup 选择没有类的 HTML 元素

    考虑一个像这样的 html 文档 div p p p p p class random class name p div 我们怎样才能选择所有p元素 但不包括p元素与random class name class Elements ps b

随机推荐

  • 读取/写入 Excel 2007 受密码保护的文档

    Office 2007 使用什么方法进行加密 当从 Office 菜单中选择 加密 并设置密码时 我的 C 应用程序需要创建和读取加密的 Excel 2007 文件 xlsx 重要的是这些文件仍然可以从 Excel 访问 因此我必须使用 M
  • 更改 BlobBuilder 中的文件名以作为 XHR 上的 FormData 传递

    我目前正在尝试将 ArrayBuffer 上传到服务器 我无法更改 该服务器需要我以多部分 表单数据格式上传的文件 服务器从Content Disposition部分的filename将被保存并在Content type提供文件时将使用的
  • 当计算使用后台线程时,如何正确声明计算属性?

    我试图声明一个由块组成的计算属性 在后台线程中执行 因此 当我处理这个属性时 它是零 因为计算在未准备好时返回结果 如何更好地纠正这个问题 谢谢你 enum Result
  • NestJS CLI 输出垃圾

    我已经使用过 NestJS 相当多了 而且它也是 CLI 但是当我现在想使用它时 它开始输出垃圾 我尝试的每个命令 nest nest info nest new npm run start dev This started happeni
  • 如何防止 app.config 集成到 .net 库 (dll) 中

    当我编译库时 Settings Settings 中的所有设置都集成到 DLL 中 我该如何防止这种情况 查看Settings settings文件的属性 并将 构建操作 设置为 资源 将 复制到输出目录 设置为 不复制 这应该会创建一个
  • Symfony 6无法使用mailer发送电子邮件(未配置数据库)

    大家好 我刚刚开始使用 Symfony6 构建网络 我尝试使用邮件程序发送电子邮件 但它以某种方式需要配置数据库 为消息创建一些特殊表 也许有一些解决方法 因此它可以在没有数据库的情况下工作 在 Symfony 5 中没有问题 如果在 co
  • 检查 Python While 循环中的值是否仍然保持不变

    我想知道是否有一种优雅的方法来查看是否可以检查在 while 循环中不断变化的值 并在该值停止变化并保持不变时停止 while 循环 例如 Value 0 while True value changes everytime if valu
  • 借助 PHP 和 HTML 动态创建行和列

    我想在 PHP 和 HTML 的帮助下创建动态行和列 但我对这段代码有点困惑 因此非常感谢一些帮助 table table 场景很简单 Mysql 数据从 for each 循环返回 6 条记录 结果将如下图所示 同样的方式 Mysql 数
  • 在 array.xml 中添加超链接文本

    我正在使用 array xml 创建列表并将其填充到 listView 中 问题是我需要在 arrayItem 描述中添加一个超链接文本 这样当我将其填充到 listView 中时 它应该链接到我的网站
  • 我是否需要 Content-Type: application/octet-stream 来下载文件?

    The HTTP标准 says 如果在响应中使用此标头 Content Disposition Attachment 对于 application octet stream 内容类型 隐含的 建议用户代理不应显示响应 但是 直接进入 将响应
  • java泛型,如何从两个类扩展?

    我想要一个 Class 对象 但我想强制它所代表的任何类扩展 A 类和 B 类 我可以
  • 如何在 C# 中获取对象的小写名称(即使为 null)[重复]

    这个问题在这里已经有答案了 我有C 方法 private static string TypeNameLower object o return o GetType Name ToLower 给我输入对象的小写类型名称 但是 如果输入是设置
  • C# WCF - 客户端/服务器 - System.OutOfMemory 异常

    问题 使用 Net TCP 绑定 发布者 订阅者模式 的 C WCF 客户端 服务器应用程序 客户端不断崩溃OutOfMemoryException 当我与客户端一起运行任务管理器时 我可以看到 内存使用情况 列不断增加 直到应用程序崩溃
  • java.net.Socket TCP keep-alive 用法

    如何使用java net Socket setKeepAlive boolean b API 我正在使用一个简单的服务器托管Socket 客户端可以连接并发送数据 除非客户端发送流结束 否则我不会关闭连接 客户端可以继续保持连接任意时间 数
  • 如何为EBS和RDS创建VPC?

    我制作了一个 Django 应用程序并将其部署在Elastic Beanstalk 我做了一个 Postgres DBRDS以及 我想将这两个添加到VPC 我创建了VPC使用专有网络向导 具有公共和私有子网的 VPC 顾名思义 它创建了1
  • 使用 Javascript 单击时显示 1 个 div 并隐藏所有其他 div

    我正在我的网站上设置一个 个人简介 部分 我有 3 张员工图片和 3 个 div 每个员工的个人简介如下 我想默认隐藏所有BIOS 然后仅显示与单击的图像关联的div 并隐藏所有其他div 目前看来它没有找到元素 因为我得到 未定义 这是到
  • XPath获取最大ID

    XML 来源
  • CSS 防止 div flex 拉伸子元素

    div 的时刻flexdisplay 属性会拉伸段落 我似乎遗漏了一些东西 但我认为放在 Flex div 上的任何属性都不会改变这一点 我怎样才能防止这种行为 没有 flex 属性 我得到图像右侧的结果 div display flex
  • String(contentsOf url:URL) 可能会抛出什么类型的异常?

    我正处于重构原型以使其更加灵活的阶段 这意味着我想添加错误处理 我的应用程序非常依赖 String contentsOf url 与处理文件的任何操作一样 它很容易出错 然而 相关 init 方法的签名只是这样写 init contents
  • 无法打开数据库/无法将(数据库)的区域设置更改为“en_US”

    我已阅读解决方案无法将数据库 data data my easymedi controller databases EasyMediInfo db 的区域设置更改为 en US 但这对我没有帮助 我仍然有同样的错误 这些是我的DBHelpe