Autore Topic: errore sqlite  (Letto 720 volte)

Offline tafazzi87

  • Nuovo arrivato
  • *
  • Post: 31
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Google nexus 7 - acer E330
  • Sistema operativo:
    Ubuntu 12.04 - Mac OS X 10.6.8
errore sqlite
« il: 20 Giugno 2013, 12:54:52 CEST »
0
ragazzi io ho un database sqlite già fatto e che devo usare per una mia applicazione, purtroppo non riesco a connetterlo all'applicazione, sto andando fuori di testa...
ho seguito questa guida per collegare e usare il db:http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
purtroppo non ne riesco a venire a capo di questo problema, mi potete aiutare perfavore???
Qui i pastebin del progetto:
MainActivity.java
Codice (Java): [Seleziona]
package com.example.provadatabase;
 
import java.util.List;
 
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
 
public class MainActivity extends Activity implements android.view.View.OnClickListener{
    private DataSource db;
    private Button bu;
        @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MyOpenHelper o=new MyOpenHelper(this);
        db=new DataSource(o);
        db.open();
        bu=(Button) findViewById(R.id.button1);
        bu.setOnClickListener(this);
    }
 
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
        public void onClick(View v) {
                // TODO Auto-generated method stub
                List<Coordinate> lista=db.vediCoordinate();
                ListView l=(ListView) findViewById(R.id.listView1);
                ArrayAdapter<Coordinate> a=new ArrayAdapter<Coordinate>(this, android.R.layout.simple_list_item_1,lista);
                l.setAdapter(a);
        }
   
   
}
DataSource.java
Codice (Java): [Seleziona]
package com.example.provadatabase;
 
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
 
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
 
public class DataSource {
        private MyOpenHelper oh;
        public DataSource (MyOpenHelper o){
                oh=o;
        }
        public void open(){
                try{
                        oh.createDataBase();
                }catch (IOException e){
                        throw new Error("Non posso creare il database");
                }
                try{
                        oh.openDataBase();
                }catch(SQLException sql){
                        sql.printStackTrace();
                }
        }
        public List<Coordinate> vediCoordinate(){
                SQLiteDatabase db=oh.getReadableDatabase();
                String c[]=new String[]{"lat","long"};
                Cursor cu=db.query("linee", c, null, null, null, null, null);
                int rows=cu.getCount();
                ArrayList<Coordinate> risultato=new ArrayList<Coordinate>(rows);
                cu.moveToFirst();
                for(int i=0;i<rows;i++){
                        risultato.add(i, new Coordinate(cu.getDouble(1),cu.getDouble(2)));
                        cu.moveToNext();
                }
                cu.close();
                return risultato;      
        }
}
MyOpenHelper.java
Codice (Java): [Seleziona]
package com.example.provadatabase;
 
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.SQLException;
 
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
 
public class MyOpenHelper extends SQLiteOpenHelper{
                 
            //The Android's default system path of your application database.
            private static String DB_PATH = "/data/data/com.example.provadatabase/databases/";
         
            private static String DB_NAME = "orari";
         
            private SQLiteDatabase myDataBase;
         
            private final Context myContext;
         
            /**
             * Constructor
             * Takes and keeps a reference of the passed context in order to access to the application assets and resources.
             * @param context
             */

            public MyOpenHelper(Context context) {
         
                super(context, DB_NAME, null, 1);
                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();
         
                if(dbExist){
                        //do nothing - database already exist
                }else{
         
                        //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 {
         
                                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;
         
                try{
                        String myPath = DB_PATH + DB_NAME;
                        checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
         
                }catch(SQLiteException e){
         
                        //database does't exist yet.
         
                }
         
                if(checkDB != null){
         
                        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 void openDataBase() throws SQLException{
         
                //Open the database
                String myPath = DB_PATH + DB_NAME;
                myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
         
            }
         
            @Override
                public synchronized void close() {
         
                    if(myDataBase != null)
                            myDataBase.close();
         
                    super.close();
         
            }
                @Override
                public void onCreate(SQLiteDatabase db) {
                        // TODO Auto-generated method stub
                       
                }
 
                @Override
                public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                        // TODO Auto-generated method stub
                       
                }
         
                // 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.
         
        }
LOGCAT AVD
Codice: [Seleziona]
06-20 10:08:55.788: E/Trace(1262): error opening trace file: No such file or directory (2)
06-20 10:09:01.298: E/SQLiteLog(1262): (1) no such table: linee
06-20 10:09:01.338: E/AndroidRuntime(1262): FATAL EXCEPTION: main
06-20 10:09:01.338: E/AndroidRuntime(1262): android.database.sqlite.SQLiteException: no such table: linee (code 1): , while compiling: SELECT lat, long FROM linee
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at com.example.provadatabase.DataSource.vediCoordinate(DataSource.java:31)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at com.example.provadatabase.MainActivity.onClick(MainActivity.java:36)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.view.View.performClick(View.java:4204)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.view.View$PerformClick.run(View.java:17355)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.os.Handler.handleCallback(Handler.java:725)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.os.Looper.loop(Looper.java:137)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at android.app.ActivityThread.main(ActivityThread.java:5041)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at java.lang.reflect.Method.invokeNative(Native Method)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at java.lang.reflect.Method.invoke(Method.java:511)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-20 10:09:01.338: E/AndroidRuntime(1262):     at dalvik.system.NativeStart.main(Native Method)
LOGCAT MIO DEVICE
Codice: [Seleziona]
06-20 12:40:08.291: E/SqliteDatabaseCpp(19239): sqlite3_open_v2("/data/data/com.example.provadatabase/databases/orari", &handle, 1, NULL) failed
06-20 12:40:08.296: E/SQLiteDatabase(19239): Failed to open the database. closing it.
06-20 12:40:08.296: E/SQLiteDatabase(19239): android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1013)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:962)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at com.example.provadatabase.MyOpenHelper.checkDataBase(MyOpenHelper.java:74)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at com.example.provadatabase.MyOpenHelper.createDataBase(MyOpenHelper.java:41)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at com.example.provadatabase.MainActivity.onCreate(MainActivity.java:24)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at android.app.Activity.performCreate(Activity.java:4465)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at android.os.Looper.loop(Looper.java:137)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at android.app.ActivityThread.main(ActivityThread.java:4424)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at java.lang.reflect.Method.invokeNative(Native Method)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at java.lang.reflect.Method.invoke(Method.java:511)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
06-20 12:40:08.296: E/SQLiteDatabase(19239):    at dalvik.system.NativeStart.main(Native Method)
06-20 12:40:08.369: E/SqliteDatabaseCpp(19239): SELECT locale FROM android_metadata failed
06-20 12:40:08.371: E/SQLiteDatabase(19239): Failed to open the database. closing it.
06-20 12:40:08.371: E/SQLiteDatabase(19239): android.database.sqlite.SQLiteException: no such table: android_metadata
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.database.sqlite.SQLiteDatabase.native_setLocale(Native Method)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.database.sqlite.SQLiteDatabase.setLocale(SQLiteDatabase.java:2074)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1014)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:962)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at com.example.provadatabase.MyOpenHelper.openDataBase(MyOpenHelper.java:125)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at com.example.provadatabase.MainActivity.onCreate(MainActivity.java:29)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.app.Activity.performCreate(Activity.java:4465)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.os.Looper.loop(Looper.java:137)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at android.app.ActivityThread.main(ActivityThread.java:4424)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at java.lang.reflect.Method.invokeNative(Native Method)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at java.lang.reflect.Method.invoke(Method.java:511)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
06-20 12:40:08.371: E/SQLiteDatabase(19239):    at dalvik.system.NativeStart.main(Native Method)
06-20 12:40:08.377: E/AndroidRuntime(19239): FATAL EXCEPTION: main
06-20 12:40:08.377: E/AndroidRuntime(19239): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.provadatabase/com.example.provadatabase.MainActivity}: android.database.sqlite.SQLiteException: no such table: android_metadata
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.os.Looper.loop(Looper.java:137)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.app.ActivityThread.main(ActivityThread.java:4424)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at java.lang.reflect.Method.invokeNative(Native Method)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at java.lang.reflect.Method.invoke(Method.java:511)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at dalvik.system.NativeStart.main(Native Method)
06-20 12:40:08.377: E/AndroidRuntime(19239): Caused by: android.database.sqlite.SQLiteException: no such table: android_metadata
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.database.sqlite.SQLiteDatabase.native_setLocale(Native Method)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.database.sqlite.SQLiteDatabase.setLocale(SQLiteDatabase.java:2074)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1014)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:962)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at com.example.provadatabase.MyOpenHelper.openDataBase(MyOpenHelper.java:125)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at com.example.provadatabase.MainActivity.onCreate(MainActivity.java:29)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.app.Activity.performCreate(Activity.java:4465)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-20 12:40:08.377: E/AndroidRuntime(19239):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-20 12:40:08.377: E/AndroidRuntime(19239):    ... 11 more

Offline Sakazaki

  • Utente normale
  • ***
  • Post: 396
  • Respect: +74
    • Mostra profilo
  • Dispositivo Android:
    Sony xperia Z
  • Play Store ID:
    Saka Labs
  • Sistema operativo:
    Windows 8
Re:errore sqlite
« Risposta #1 il: 20 Giugno 2013, 13:44:23 CEST »
0
Manca nel database la tabella android_metadata, che ci deve sempre essere. Se spulci per la rete trovi sicuramente indicazioni su come dev'essere fatta e cosa deve contenere.

Offline tafazzi87

  • Nuovo arrivato
  • *
  • Post: 31
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Google nexus 7 - acer E330
  • Sistema operativo:
    Ubuntu 12.04 - Mac OS X 10.6.8
Re:errore sqlite
« Risposta #2 il: 20 Giugno 2013, 14:54:57 CEST »
0
Manca nel database la tabella android_metadata, che ci deve sempre essere. Se spulci per la rete trovi sicuramente indicazioni su come dev'essere fatta e cosa deve contenere.
provo subito grazie della risposta!!! speriamo di risolvere  ;-)

Post unito: 20 Giugno 2013, 16:07:35 CEST
niente ho messo una tabella all'itnerno del database chiamata android_metadata e con un unica colonna chiamata locale e unico record chiamato it_IT ( ho provato anche en_US) ma mi da questo errore sempre:
Codice: [Seleziona]
03-28 20:51:39.524: E/SQLiteLog(2235): (1) no such column: locale
03-28 20:51:39.583: E/SQLiteDatabase(2235): Failed to open database '/data/data/com.example.provadatabase/databases/orari'.
03-28 20:51:39.583: E/SQLiteDatabase(2235): android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/com.example.provadatabase/databases/orari' to 'en_US'.
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:386)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:218)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:854)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:229)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at com.example.provadatabase.DataSource.vediCoordinate(DataSource.java:18)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at com.example.provadatabase.MainActivity.onClick(MainActivity.java:47)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.view.View.performClick(View.java:4202)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.view.View$PerformClick.run(View.java:17340)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.os.Handler.handleCallback(Handler.java:725)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.os.Handler.dispatchMessage(Handler.java:92)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.os.Looper.loop(Looper.java:137)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.app.ActivityThread.main(ActivityThread.java:5039)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at java.lang.reflect.Method.invokeNative(Native Method)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at java.lang.reflect.Method.invoke(Method.java:511)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at dalvik.system.NativeStart.main(Native Method)
03-28 20:51:39.583: E/SQLiteDatabase(2235): Caused by: android.database.sqlite.SQLiteException: no such column: locale (code 1): , while compiling: SELECT locale FROM android_metadata UNION SELECT NULL ORDER BY locale DESC LIMIT 1
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:627)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:367)
03-28 20:51:39.583: E/SQLiteDatabase(2235):         ... 25 more
03-28 20:51:39.623: E/SQLiteOpenHelper(2235): Couldn't open orari for writing (will try read-only):
03-28 20:51:39.623: E/SQLiteOpenHelper(2235): android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/com.example.provadatabase/databases/orari' to 'en_US'.
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:386)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:218)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:854)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:229)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at com.example.provadatabase.DataSource.vediCoordinate(DataSource.java:18)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at com.example.provadatabase.MainActivity.onClick(MainActivity.java:47)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.view.View.performClick(View.java:4202)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.view.View$PerformClick.run(View.java:17340)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.os.Handler.handleCallback(Handler.java:725)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.os.Handler.dispatchMessage(Handler.java:92)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.os.Looper.loop(Looper.java:137)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.app.ActivityThread.main(ActivityThread.java:5039)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at java.lang.reflect.Method.invokeNative(Native Method)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at java.lang.reflect.Method.invoke(Method.java:511)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at dalvik.system.NativeStart.main(Native Method)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235): Caused by: android.database.sqlite.SQLiteException: no such column: locale (code 1): , while compiling: SELECT locale FROM android_metadata UNION SELECT NULL ORDER BY locale DESC LIMIT 1
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:627)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:367)
03-28 20:51:39.623: E/SQLiteOpenHelper(2235):         ... 25 more
03-28 20:51:39.683: E/AndroidRuntime(2235): FATAL EXCEPTION: main
03-28 20:51:39.683: E/AndroidRuntime(2235): android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 0 to 1: orari
03-28 20:51:39.683: E/AndroidRuntime(2235):         at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:245)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at com.example.provadatabase.DataSource.vediCoordinate(DataSource.java:18)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at com.example.provadatabase.MainActivity.onClick(MainActivity.java:47)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at android.view.View.performClick(View.java:4202)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at android.view.View$PerformClick.run(View.java:17340)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at android.os.Handler.handleCallback(Handler.java:725)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at android.os.Handler.dispatchMessage(Handler.java:92)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at android.os.Looper.loop(Looper.java:137)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at android.app.ActivityThread.main(ActivityThread.java:5039)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at java.lang.reflect.Method.invokeNative(Native Method)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at java.lang.reflect.Method.invoke(Method.java:511)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-28 20:51:39.683: E/AndroidRuntime(2235):         at dalvik.system.NativeStart.main(Native Method)
« Ultima modifica: 20 Giugno 2013, 16:07:35 CEST da tafazzi87, Reason: Merged DoublePost »

Offline Sakazaki

  • Utente normale
  • ***
  • Post: 396
  • Respect: +74
    • Mostra profilo
  • Dispositivo Android:
    Sony xperia Z
  • Play Store ID:
    Saka Labs
  • Sistema operativo:
    Windows 8
Re:errore sqlite
« Risposta #3 il: 20 Giugno 2013, 16:12:51 CEST »
0
Però, come si vede dal logcat, stavolta la tabella l'ha trovata; non gli risulta la colonna locale. :)
Controlla bene se la colonna c'è e se si chiama correttamente. Una svista ci può stare.

Offline tafazzi87

  • Nuovo arrivato
  • *
  • Post: 31
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Google nexus 7 - acer E330
  • Sistema operativo:
    Ubuntu 12.04 - Mac OS X 10.6.8
Re:errore sqlite
« Risposta #4 il: 20 Giugno 2013, 16:23:35 CEST »
0
no c'è ne sono sicuro...qui c'è uno screenshot del database :http://img62.imageshack.us/img62/2184/l09.png

Offline Sakazaki

  • Utente normale
  • ***
  • Post: 396
  • Respect: +74
    • Mostra profilo
  • Dispositivo Android:
    Sony xperia Z
  • Play Store ID:
    Saka Labs
  • Sistema operativo:
    Windows 8
Re:errore sqlite
« Risposta #5 il: 21 Giugno 2013, 09:49:47 CEST »
+1
Scusa il ritardo nella risposta, ma solo oggi sono riuscito a leggere il topic da un pc (ho sempre risposto da cellulare).
Adesso che ho potuto leggere il codice che avevi postato posso riassumo le due alternative che puoi adottare per risolvere il problema:

1) rimuovi pure la tabella android_metadata dal tuo db (poi spiego perché).

2) quando in MyOpenHelper fai SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY) invece di usare il flag OPEN_READONLY puoi usare OPEN_READWRITE, android crea automaticamente la tabella.

2b) se non vuoi usare il flag OPEN_READWRITE (ci possono essere ottimi motivi per voler accedere in sola lettura), e i tuoi dati non necessitano di localizzazione, puoi concatenare il flag NO_LOCALIZED_COLLATORS: SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY|SQLiteDatabase.NO_LOCALIZED_COLLATORS) che istruisce android ad ignorare il supporto del locale ed evita che cerchi la tabella specifica.

Offline tafazzi87

  • Nuovo arrivato
  • *
  • Post: 31
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Google nexus 7 - acer E330
  • Sistema operativo:
    Ubuntu 12.04 - Mac OS X 10.6.8
Re:errore sqlite
« Risposta #6 il: 21 Giugno 2013, 10:29:09 CEST »
0
ok grazie mille adesso dà un altro tipo di problema, vedo se riesco a risolverlo...però almeno così non mi da sempre lo stesso problema :D
LOGCAT
Codice: [Seleziona]
06-21 08:23:57.127: E/SQLiteLog(840): (14) cannot open file at line 30176 of [00bb9c9ce4]
06-21 08:23:57.127: E/SQLiteLog(840): (14) os_unix.c:30176: (2) open(/data/data/com.example.provadatabase/databases/orari) -
06-21 08:23:57.147: E/SQLiteDatabase(840): Failed to open database '/data/data/com.example.provadatabase/databases/orari'.
06-21 08:23:57.147: E/SQLiteDatabase(840): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database

Post unito: 21 Giugno 2013, 10:47:53 CEST
ok risolto...ho aggiunto questo al costruttore di MyOpenHelper
Codice (Java): [Seleziona]
    if(android.os.Build.VERSION.SDK_INT >= 4.2){
        DB_PATH = context.getApplicationInfo().dataDir + "/databases/";        
    } else {
       DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
    }
il problema era le differenti versioni di sdk....grazie mille per la tua pazienza!!!
« Ultima modifica: 21 Giugno 2013, 10:47:53 CEST da tafazzi87, Reason: Merged DoublePost »