开发者

rawQuery - CursorAdapter

App gets force closed when going to this activity. I actual开发者_Go百科ly 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);



}

}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜