Java 类android.database.sqlite.SQLiteCantOpenDatabaseException 实例源码

项目:OpenXiaomiScale    文件:Database.java   
private boolean existsDatabase()
{
    SQLiteDatabase database = null;
    boolean isExist = true;

    try
    {
        database = SQLiteDatabase.openDatabase(DB_PATH, null, SQLiteDatabase.OPEN_READONLY);
    }
    catch (SQLiteCantOpenDatabaseException e)
    {
        // No database
        Log.d("Database", "Database not found!");
        isExist = false;
    }
    finally
    {
        if ( database != null )
            database.close();
    }

    return isExist;
}
项目:android-job    文件:JobStorage.java   
@NonNull
@VisibleForTesting
/*package*/ SQLiteDatabase getDatabase() {
    if (mInjectedDatabase != null) {
        return mInjectedDatabase;
    } else {
        try {
            return mDbHelper.getWritableDatabase();

        } catch (SQLiteCantOpenDatabaseException e) {
            CAT.e(e);

            // that's bad, delete the database and try again, otherwise users may get stuck in a loop
            new JobStorageDatabaseErrorHandler().deleteDatabaseFile(DATABASE_NAME);
            return mDbHelper.getWritableDatabase();
        }
    }
}
项目:terraingis    文件:TileCache.java   
/**
 * open cache file
 * @param file
 */
public void open(File file, Resources resources, MapView map)
    throws SQLiteCantOpenDatabaseException
{
    mResources = resources;
    mMap = map;

    boolean exists = file.exists();

    mDB = SQLiteDatabase.openOrCreateDatabase(file, null);

    if(!exists)
    {
        mDB.execSQL(CREATE_CACHE_TABLE);
    }
}
项目:requery    文件:BaseConnection.java   
public static void throwSQLException(android.database.SQLException exception)
    throws SQLException {

    if(exception instanceof SQLiteConstraintException) {
        throw new SQLIntegrityConstraintViolationException(exception);

    } else if(exception instanceof SQLiteCantOpenDatabaseException ||
        exception instanceof SQLiteDatabaseCorruptException ||
        exception instanceof SQLiteAccessPermException) {

        throw new SQLNonTransientException(exception);
    }
    throw new SQLException(exception);
}
项目:txtr    文件:DatabaseBackend.java   
public boolean hasEnabledAccounts() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery("select count(" + Account.UUID + ")  from "
            + Account.TABLENAME + " where not options & (1 <<1)", null);
    try {
        cursor.moveToFirst();
        int count = cursor.getInt(0);
        cursor.close();
        return (count > 0);
    } catch (SQLiteCantOpenDatabaseException e) {
        return true; // better safe than sorry
    }
}
项目:PebbleNotificationCenter-Android    文件:NotificationHistoryStorage.java   
public void storeNotification(long time, String title, String subtitle, String text, Bitmap icon)
{
    ContentValues values = new ContentValues();
    values.put("PostTime", time);
    values.put("Title", title);
    values.put("Subtitle", subtitle);
    values.put("Text", text);

    if (icon == null)
        values.put("Icon", (byte[]) null);
    else
    {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        icon.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
        values.put("Icon", byteArrayOutputStream.toByteArray());
    }

    try
    {
        getWritableDatabase().insert("notifications", null, values);
    }
    catch (SQLiteCantOpenDatabaseException e)
    {
        Timber.e(e, "Database open exception!");
        e.printStackTrace();
    }
}
项目:openbmap    文件:WirelessLoggerService.java   
@SuppressWarnings("deprecation")
@Override
public final void onCreate() {      
    Log.d(TAG, "WirelessLoggerService created");
    super.onCreate();

    final Notification note = new Notification(R.drawable.icon_greyed_25x25, getString(R.string.notification_caption), System.currentTimeMillis());
    final Intent i = new Intent(this, HostActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
    final PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);
    note.setLatestEventInfo(this, getString(R.string.app_name), getString(R.string.notification_caption), pi);
    note.flags|=Notification.FLAG_NO_CLEAR;

    //Notification note = new Notification(R.drawable.icon_greyed_25x25, getString(R.string.notification_caption), System.currentTimeMillis());
    //note.flags |= Notification.FLAG_NO_CLEAR;
    startForeground(NOTIFICATION_ID, note);

    // get shared preferences
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    if (!prefs.getString(Preferences.KEY_WIFI_CATALOG_FILE, Preferences.VAL_WIFI_CATALOG_FILE).equals(Preferences.VAL_WIFI_CATALOG_NONE)) {
        final String catalogPath = prefs.getString(Preferences.KEY_WIFI_CATALOG_FOLDER,
                getApplicationContext().getExternalFilesDir(null).getAbsolutePath() + File.separator + Preferences.WIFI_CATALOG_SUBDIR)
                + File.separator + prefs.getString(Preferences.KEY_WIFI_CATALOG_FILE, Preferences.VAL_WIFI_CATALOG_FILE);

        try {
            mRefDb = SQLiteDatabase.openDatabase(catalogPath, null, SQLiteDatabase.OPEN_READONLY);
        } catch (final SQLiteCantOpenDatabaseException ex) {
            Log.e(TAG, "Can't open wifi catalog database @ " + catalogPath);
            mRefDb = null;
        }
    } else {
        Log.w(TAG, "No wifi catalog selected. Can't compare scan results with openbmap dataset.");
    }

    /*
     * Setting up database connection
     */
    mDataHelper = new DataHelper(this);

    registerWakeLocks();

    registerPhoneStateManager();

    registerWifiManager();

    initBlacklists();
}
项目:radiocells-scanner-android    文件:WifiDetailsActivity.java   
/**
 * @param wifi
 */
private void displayRecord(final WifiRecord wifi) {

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    if (wifi == null) {
        Log.e(TAG, "Wifi argument was null");
        return;
    }

    if (!prefs.getString(Preferences.KEY_CATALOG_FILE, Preferences.VAL_CATALOG_NONE).equals(Preferences.VAL_CATALOG_NONE)) {
        // Open catalog database
        final String file = prefs.getString(Preferences.KEY_WIFI_CATALOG_FOLDER,
                this.getExternalFilesDir(null).getAbsolutePath() + File.separator + Preferences.CATALOG_SUBDIR)
                + File.separator + prefs.getString(Preferences.KEY_CATALOG_FILE, Preferences.VAL_CATALOG_FILE);
        try {
            final SQLiteDatabase mCatalog = SQLiteDatabase.openDatabase(file, null, SQLiteDatabase.OPEN_READONLY);
            Cursor cur = null;
            cur = mCatalog.rawQuery("SELECT _id, manufactor FROM manufactors WHERE "
                            + "(bssid = ?) LIMIT 1",
                    new String[]{wifi.getBssid().replace(":", "").replace("-", "").substring(0, 6).toUpperCase()});

            if (cur.moveToFirst()) {
                final String manufactor = cur.getString(cur.getColumnIndex("manufactor"));
                tvManufactor.setText(manufactor);
            }
            cur.close();
        } catch (SQLiteCantOpenDatabaseException e1) {
            Log.e(TAG, e1.getMessage());
            Toast.makeText(this, getString(R.string.error_opening_wifi_catalog), Toast.LENGTH_LONG).show();
            return;
        } catch (SQLiteException e2) {
            Log.e(TAG, e2.getMessage());
            Toast.makeText(this, R.string.error_accessing_wifi_catalog, Toast.LENGTH_LONG).show();
            return;
        }
    }

    tvSsid.setText(wifi.getSsid() + " (" + wifi.getBssid() + ")");
    if (wifi.getCapabilities() != null)

    {
        tvCapabilities.setText(wifi.getCapabilities().replace("[", "\n["));
    } else

    {
        tvCapabilities.setText(getResources().getString(R.string.n_a));
    }

    final Integer freq = wifi.getFrequency();
    if (freq != null)

    {
        tvFrequency.setText(((WifiChannel.getChannel(freq) == null) ? getResources().getString(R.string.unknown) : WifiChannel.getChannel(freq))
                        + "  (" + freq + " MHz)");
    }

    if (wifi.getCatalogStatus().equals(CatalogStatus.NEW)) {
        ivIsNew.setImageResource(android.R.drawable.checkbox_on_background);
    } else {
        ivIsNew.setImageResource(android.R.drawable.checkbox_off_background);
    }
}
项目:radiocells-scanner-android    文件:WirelessLoggerService.java   
@Override
  public final void onCreate() {
      Log.d(TAG, "WirelessLoggerService created");
      super.onCreate();

      // get shared preferences
      prefs = PreferenceManager.getDefaultSharedPreferences(this);

      if (!prefs.getString(Preferences.KEY_CATALOG_FILE, Preferences.VAL_CATALOG_FILE).equals(Preferences.VAL_CATALOG_NONE)) {
          final String catalogPath = prefs.getString(Preferences.KEY_WIFI_CATALOG_FOLDER,
                  getApplicationContext().getExternalFilesDir(null).getAbsolutePath() + File.separator + Preferences.CATALOG_SUBDIR)
                  + File.separator + prefs.getString(Preferences.KEY_CATALOG_FILE, Preferences.VAL_CATALOG_FILE);

          if (!(new File(catalogPath)).exists()) {
              Log.w(TAG, "Selected catalog doesn't exist");
              mRefDb = null;
          } else {
              try {
                  mRefDb = SQLiteDatabase.openDatabase(catalogPath, null, SQLiteDatabase.OPEN_READONLY);
              } catch (final SQLiteCantOpenDatabaseException ex) {
                  Log.e(TAG, "Can't open wifi catalog database @ " + catalogPath);
                  mRefDb = null;
              }
          }
      } else {
          Log.w(TAG, "No wifi catalog selected. Can't compare scan results with openbmap dataset.");
      }

/*
       * Setting up database connection
 */
      mDataHelper = new DataHelper(this);

      registerWakeLocks();

      registerPhoneStateManager();

      registerWifiManager();

      initBlacklists();
  }