0

App gets force closed when going to this activity. I actually noticed that if i remove the cursor part the activity doesn't crash. Help would be appreciated.

public class SearchResults extends ListActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.searchresults);



    Database myDbHelper = new Database(null);
    myDbHelper = new Database(this);

    try {
        myDbHelper.createDataBase();

    } catch (IOException ioe) {

        throw new Error("Unable to create database");
        }

try {



}catch(SQLException sqle){

    throw sqle;

  }



    // Get the intent, verify the action and get the query
    Intent intent = getIntent();
    String query = intent.getStringExtra(SearchManager.QUERY);


    SQLiteDatabase myDb = myDbHelper.getReadableDatabase();
    String q = "SELECT BookTitle, _ISBN FROM Books WHERE BookTitle LIKE" + query;
    Cursor c = myDb.rawQuery(q, null);
    startManagingCursor(c);



 // the desired columns to be bound
    String[] columns = new String[] { "Books._ISBN", "Books.BookTitle" }; 
 // the XML defined views which the data will be bound to
    int[] to = new int[] { R.id.ISBN_entry, R.id.Title_entry };

    SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.listlayout, c, columns, to);
    this.setListAdapter(mAdapter);



}

}

1 Answers1

1

The Cursor requires a column called '_id' - change your query to alias your ISBN column as follows...

String q = "SELECT _ISBN as _id, BookTile FROM Books WHERE BookTitle LIKE" + query;

See my answer and explanation here column '_id' does not exist problem

Community
  • 1
  • 1
Squonk
  • 48,735
  • 19
  • 103
  • 135
  • True did not notice that but it's still something else that forces the app to force close before that. What i've figured from some experimenting is that there is something where i open the db as readable and try to get my cursor through the query. –  May 10 '11 at 01:49
  • The problem was elsewhere and this solved my problem, thanks! –  May 10 '11 at 05:39