I run on a real device, root rights are there. I suppose that the error in the code, rather than the hardware. Database copied to folder: ** app \ src \ main \ res \ assets \ database **

The error itself:

Caused by: android.database.sqlite.SQLiteException: no such table: coordinate.db (code 1): , while compiling: SELECT * FROM coordinate.db ORDER BY column DESC LIMIT 1 at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37) at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314) at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253) at com.pokemongo.pokemon.CameraViewActivity.randomCoordinate(CameraViewActivity.java:274) at com.pokemongo.pokemon.CameraViewActivity.onCreate(CameraViewActivity.java:89) at android.app.Activity.performCreate(Activity.java:5236) 

The method in which coordinates are taken randomly from the table:

 private void randomCoordinate() { ArrayList<Double> latitudesAr = new ArrayList<Double>(); ArrayList<Double> longitudesAr = new ArrayList<Double>(); String queryLatitude = "SELECT * FROM coordinate.db ORDER BY column DESC LIMIT 1"; String queryLongitude = "SELECT * FROM coordinate.db ORDER BY column DESC LIMIT 1"; Cursor cLatitude = sqlHelper.getWritableDatabase().rawQuery(queryLatitude, null); Cursor cLongitude = sqlHelper.getWritableDatabase().rawQuery(queryLongitude, null); if(cLatitude != null) { while(cLatitude.moveToNext()){ latitudesAr.add(cLatitude.getDouble(cLatitude.getColumnIndex(DatabaseHelper.LATITUDE))); } } if(cLongitude != null) { while(cLongitude.moveToNext()){ longitudesAr.add(cLatitude.getDouble(cLatitude.getColumnIndex(DatabaseHelper.LONGITUDE))); } } //получаем рандомно выбранные индексы Random r = new Random(); int indexLatitude = r.nextInt(latitudesAr.size()); int indexLongitude = r.nextInt(longitudesAr.size()); //присваиваем переменным mMyLatitude = latitudesAr.get(indexLatitude); mMyLongitude = longitudesAr.get(indexLongitude); } 

swears at this line:

  Cursor cLatitude = sqlHelper.getWritableDatabase().rawQuery(queryLatitude, null); 

I call in the oncreate method of the main class randomCoordinate ();

DB class:

 public class DatabaseHelper extends SQLiteOpenHelper { private static String DB_PATH = "/data/data/com.pokemongo.pokemon.database/databases/"; public static String DB_NAME = "coordinate.db"; private static final int SCHEMA = 1; // версия базы данных static final String TABLE = "users"; public static final String COLUMN_ID = "_id"; public static final String LATITUDE = "latitude"; public static final String LONGITUDE = "longitude"; public SQLiteDatabase database; private Context myContext; public DatabaseHelper(Context context) { super(context, DB_NAME, null, SCHEMA); this.myContext=context; } @Override public void onCreate(SQLiteDatabase db) { } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } public void create_db() { InputStream myInput = null; OutputStream myOutput = null; try { File file = new File(DB_PATH + DB_NAME); if (!file.exists()) { this.getReadableDatabase(); //получаем локальную бд как поток myInput = myContext.getAssets().open(DB_NAME); // Путь к новой бд String outFileName = DB_PATH + DB_NAME; // Открываем пустую бд myOutput = new FileOutputStream(outFileName); // побайтово копируем данные byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer)) > 0) { myOutput.write(buffer, 0, length); } myOutput.flush(); myOutput.close(); myInput.close(); } } catch (IOException ex) { } } public void open() throws SQLException { String path = DB_PATH + DB_NAME; database = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READWRITE); } @Override public synchronized void close() { if (database != null) { database.close(); } super.close(); } 

}

UPDATE: method:

 private void randomCoordinate() { ArrayList<Double> latitudesAr = new ArrayList<Double>(); ArrayList<Double> longitudesAr = new ArrayList<Double>(); String queryLatitude = "SELECT * FROM coordinates ORDER BY _id DESC LIMIT 1"; String queryLongitude = "SELECT * FROM coordinates ORDER BY _id DESC LIMIT 1"; Cursor cLatitude = sqlHelper.getWritableDatabase().rawQuery(queryLatitude, null); Cursor cLongitude = sqlHelper.getWritableDatabase().rawQuery(queryLongitude, null); if (cLatitude != null) { while (cLatitude.moveToNext()) { latitudesAr.add(cLatitude .getDouble(cLatitude.getColumnIndex(DatabaseHelper.LATITUDE))); } } if (cLongitude != null) { while (cLongitude.moveToNext()) { longitudesAr.add(cLatitude .getDouble(cLatitude.getColumnIndex(DatabaseHelper.LONGITUDE))); } } //получаем рандомно выбранные индексы Random r = new Random(); int indexLatitude = r.nextInt(latitudesAr.size()); int indexLongitude = r.nextInt(longitudesAr.size()); //присваиваем переменным mMyLatitude = latitudesAr.get(indexLatitude); mMyLongitude = longitudesAr.get(indexLongitude); } 

enter image description here

UPDATE 2

  private void randomCoordinate() { ArrayList<Double> latitudesAr = new ArrayList<Double>(); ArrayList<Double> longitudesAr = new ArrayList<Double>(); String queryLatitude = "SELECT * FROM \" + coordinates + \" ORDER BY \" + id +\" DESC LIMIT 1"; String queryLongitude = "SELECT * FROM \" + coordinates + \" ORDER BY \" + id +\" DESC LIMIT 1"; try { Cursor cLatitude = sqlHelper.getWritableDatabase().rawQuery(queryLatitude, null); Cursor cLongitude = sqlHelper.getWritableDatabase().rawQuery(queryLongitude, null); if (cLatitude != null) { while (cLatitude.moveToNext()) { latitudesAr.add(cLatitude .getDouble(cLatitude.getColumnIndex(DatabaseHelper.LATITUDE))); } } if (cLongitude != null) { while (cLongitude.moveToNext()) { longitudesAr.add(cLongitude .getDouble(cLongitude.getColumnIndex(DatabaseHelper.LONGITUDE))); } } } catch (Exception e) { Toast.makeText(getApplicationContext(), "ошибка получения колонок бд", Toast.LENGTH_SHORT) .show(); } //получаем рандомно выбранные индексы Random r = new Random(); int indexLatitude = r.nextInt(latitudesAr.size()); int indexLongitude = r.nextInt(longitudesAr.size()); //присваиваем переменным mMyLatitude = latitudesAr.get(indexLatitude); mMyLongitude = longitudesAr.get(indexLongitude); } 

Error: falls out here:

  int indexLatitude = r.nextInt(latitudesAr.size()); 

Caused by: java.lang.IllegalArgumentException: n <= 0: 0

    1 answer 1

    In a SQL query, after SELECT * FROM, there must be some sort of table in the database, not the name of the base itself. The error says that there is no table in the database with the name coordinate.db, which is natural.

    The name of the table you, apparently, users , judging by the constants, although the SQL command to create the database is not, as you copy it and the names of the tables in your database know only you.

    Ps. Sorting by some field (column) column also looks very suspicious, you are sure that there is such a column in your table.

    • He took into account all your comments, but nothing helped! updated cap - upward
    • @upward what's the error now? - pavlofff
    • @ pavlofff is the same, I attached the screenshot - upward
    • @ pavlofff found an error, oglvil code, now another) but not from this song - upward
    • @upward Since this is a completely different problem, create a new question. Give this question in its original form so that the answer matches the question, these are the rules of this resource. If my answer solved the original problem, mark it correct - pavlofff