Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法获取可写数据库。SQLiteException:不是错误(代码0)_Java_Android_Database_Sqlite - Fatal编程技术网

Java 无法获取可写数据库。SQLiteException:不是错误(代码0)

Java 无法获取可写数据库。SQLiteException:不是错误(代码0),java,android,database,sqlite,Java,Android,Database,Sqlite,当我尝试使用SQLiteOpenHelper获取可写(和可读)数据库时,收到错误: E/SQLiteDatabase: Failed to open database '/data/user/0/com.smt/databases/SMT'. android.database.sqlite.SQLiteException: not an error (code 0) at android.database.sqlite.SQLiteConnection.na

当我尝试使用SQLiteOpenHelper获取可写(和可读)数据库时,收到错误:

 E/SQLiteDatabase: Failed to open database '/data/user/0/com.smt/databases/SMT'.
         android.database.sqlite.SQLiteException: not an error (code 0)
         at android.database.sqlite.SQLiteConnection.nativeRegisterLocalizedCollators(Native Method)
         at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:361)
          at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:218)
         at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
          at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
         at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
        at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:835)
        at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:820)
        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:723)
        at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:669)
        at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:290)
        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
        at com.smt.model.data.db.DatabaseHelper.<init>(DatabaseHelper.java:48)
        at com.smt.model.data.db.SmtDatabase.<init>(SmtDatabase.java:48)
        at com.smt.presenter.impl.CatalogPresenterImpl.loadCatalogForParentId(CatalogPresenterImpl.java:40)
        at com.smt.view.fragment.CatalogFragment.onCreateView(CatalogFragment.java:61)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:2354)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
      at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3221)
      at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3171)
      at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
      at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:560)
      at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
      at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1322)
      at android.app.Activity.performStart(Activity.java:6777)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2696)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2819)
      at android.app.ActivityThread.-wrap12(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1532)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:154)
      at android.app.ActivityThread.main(ActivityThread.java:6321)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
未调用onCreate或onUpgrade方法

SmtDatabase.java:

public class SmtDatabase {
    private static final String TAG = SmtDatabase.class.getName();

    private Context mContext;
    private SQLiteDatabase mDatabase;

    public SmtDatabase(Context context) {
        DatabaseHelper dbHelper = new DatabaseHelper(context);
        mDatabase = dbHelper.getWritableDatabase(); // <------  Here is error
        this.mContext = context;
    }

    /* SELECT, QUERY, UPDATE Methods */
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.smt">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <!-- After there are application with activity definitions -->
</manifest>
公共类SmtDatabase{
私有静态最终字符串标记=SmtDatabase.class.getName();
私有上下文;
私有SQLITE数据库mDatabase;
公共SmtDatabase(上下文){
DatabaseHelper dbHelper=新的DatabaseHelper(上下文);
mDatabase=dbHelper.getWritableDatabase();//

我花了两天时间试图解决这个问题,但没有结果。今天我创建了一个新项目,然后复制/粘贴了所有类,这是一个解决方法。

UDP:我已经找到了出现此问题的原因。当我在Application.java类中使用下面的代码更改语言时,我输入了错误的字符串值(“ПСССц”),配置无法正确创建数据库

@Override
public void onCreate() {
    super.onCreate();
    Fabric.with(this, new Crashlytics());
    PreferenceManager mPreferenceManager = new PreferenceManager(getApplicationContext());

    mLang = mPreferenceManager.getLocale();  // Here I have got incorrect value

    if (mLang.equals("default")) mLang = getResources().getConfiguration().locale.getLanguage();

    Log.d(TAG, "onCreate: lang = " + mLang);

    mLocale = new Locale(mLang);
    Locale.setDefault(mLocale);
    Configuration config = new Configuration();
    config.locale = mLocale;
    getBaseContext().getResources().updateConfiguration(config, null);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    mLocale = new Locale(mLang);
    Locale.setDefault(mLocale);
    Configuration config = new Configuration();
    config.locale = mLocale;
    getBaseContext().getResources().updateConfiguration(config, null);
}
@Override
public void onCreate() {
    super.onCreate();
    Fabric.with(this, new Crashlytics());
    PreferenceManager mPreferenceManager = new PreferenceManager(getApplicationContext());

    mLang = mPreferenceManager.getLocale();  // Here I have got incorrect value

    if (mLang.equals("default")) mLang = getResources().getConfiguration().locale.getLanguage();

    Log.d(TAG, "onCreate: lang = " + mLang);

    mLocale = new Locale(mLang);
    Locale.setDefault(mLocale);
    Configuration config = new Configuration();
    config.locale = mLocale;
    getBaseContext().getResources().updateConfiguration(config, null);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    mLocale = new Locale(mLang);
    Locale.setDefault(mLocale);
    Configuration config = new Configuration();
    config.locale = mLocale;
    getBaseContext().getResources().updateConfiguration(config, null);
}