Note that there are some explanatory texts on larger screens.

plurals
  1. POError in asking for cursor
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/5434960/force-close-at-cursor-line">force close at cursor line!</a> </p> </blockquote> <p>I have to create an app that reads some GPS data from a Sqlite database,but everytime I try to query from the database I get force close.So I tried something simple:to insert a few lines in the database and ask for them in the program....but with something simple like this I still get force close.The thing is that when I try to run this class outside my project,it works fine. Here is my helping class for creating the database:</p> <pre><code>package test.android; import java.util.ArrayList; import java.util.List; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class CoordonateDbAdapter { public static final String KEY_ROWID = "_id"; public static final String KEY_LONGITUDE= "longitude"; public static final String KEY_LATITUDE = "latitude"; public static final String KEY_COUNTRY= "country"; public static final String KEY_TOWN= "town"; public static final String KEY_STREET = "street"; private static final String TAG = "CoordonateDbAdapter"; private DatabaseHelper mDbHelper; private SQLiteDatabase mDb; private static final String DATABASE_CREATE = "create table masini (_id integer primary key autoincrement, " + "longitude text not null, latitude text not null," + "country text not null,town text not null,street text not null);"; private static final String DATABASE_NAME = "gps"; private static final String DATABASE_TABLE = "masini"; private static final int DATABASE_VERSION = 1; private final Context mCtx; private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS notes"); onCreate(db); } } public CoordonateDbAdapter(Context ctx) { this.mCtx = ctx; } public CoordonateDbAdapter open() throws SQLException { mDbHelper = new DatabaseHelper(mCtx); mDb = mDbHelper.getReadableDatabase(); return this; } public void close() { mDbHelper.close(); } public long insertData(String longitude, String latitude, String country, String town, String street) { ContentValues initialValues = new ContentValues(); initialValues.put(KEY_LONGITUDE, longitude); initialValues.put(KEY_LATITUDE, latitude); initialValues.put(KEY_COUNTRY, country); initialValues.put(KEY_TOWN, town); initialValues.put(KEY_STREET, street); return mDb.insert(DATABASE_TABLE, null, initialValues); } public boolean deleteData(long rowId) { return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) &gt; 0; } public Cursor fetchAllData() throws SQLException{ return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_LONGITUDE,KEY_LATITUDE,KEY_COUNTRY,KEY_TOWN,KEY_STREET}, null, null, null, null, null); } public Cursor fetchData(long rowId) throws SQLException { Cursor mCursor = mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID, KEY_LONGITUDE,KEY_LATITUDE,KEY_COUNTRY,KEY_TOWN,KEY_STREET}, KEY_ROWID + "=" + rowId, null, null, null, null, null); if (mCursor != null) { mCursor.moveToFirst(); } return mCursor; } public boolean updateNote(long rowId, String longitude, String latitude,String country, String town,String street) { ContentValues args = new ContentValues(); args.put(KEY_LONGITUDE, longitude); args.put(KEY_LATITUDE, latitude); args.put(KEY_COUNTRY, country); args.put(KEY_TOWN, town); args.put(KEY_STREET, street); return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) &gt; 0; } } And the class that uses it is: package test.android; import java.util.List; import android.app.Activity; import android.database.Cursor; import android.os.Bundle; import android.widget.Toast; public class screen_database extends Activity{ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen_database); CoordonateDbAdapter db = new CoordonateDbAdapter(this); db.open(); long id; id= db.insertData("-36.2", "125","Romania","Cluj","Zorilor"); db.insertData("44", "55","Romania","Iasi","Alexandru Ioan Cuza"); Cursor c=db.fetchAllData(); } } </code></pre> <p>I tried dubugging it...and I went on my program line by line and the exception is at this line</p> <pre><code> Cursor c=db.fetchAllData(); </code></pre> <p>When I step into with the debugger it gets blocked at this line:</p> <pre><code> return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_LONGITUDE,KEY_LATITUDE,KEY_COUNTRY,KEY_TOWN,KEY_STREET}, null, null, null, null, null); </code></pre> <p>I really don't know what causes this,because outside my app it works fine.I have a lot of classes and this one is called after I go through other few intents. When I do debugging line by line,the functions are called how they should be called,from my point of few is good...I don't know what is wrong at that line.If you have any ideas I would really apreciatte it cause I'm out of it....Thank you! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload