2011-05-10 3 views
0

이 액티비티로 갈 때 앱이 강제 종료됩니다. 실제로 커서 부분을 제거하면 활동이 중단되지 않는 것으로 나타났습니다. 도움을 주시면 감사하겠습니다. 커서가 '_id'라는 열 필요rawQuery - CursorAdapter

답변

2

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); 



} 

} - 다음과 같이 ISBN 열을 별명을 쿼리 변경을 ...

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

내 대답은 여기에 설명 column '_id' does not exist problem

를 참조하십시오
+0

True는 그 사실을 알지 못했지만 여전히 앱이 강제로 닫히기 전에 강제 종료됩니다. 내가 실험에서 알게 된 것은 DB를 열어서 쿼리를 통해 커서를 가져 오는 것입니다. – GGe

+0

문제는 다른 곳에서 발생했으며 문제가 해결되었습니다. 감사합니다. – GGe

관련 문제