0
想要做的: 獲取最近搜索建議的列表,然後在listview中顯示,下面是代碼PS。數據庫中已經有了一些建議詞。嘗試從SearchRecentSuggestionsProvider獲取最近搜索建議的完整列表時出錯
......
private String string_uri = "content://com.xyz.music_search_provider/" + SearchManager.SUGGEST_URI_PATH_QUERY;
private Uri uri=Uri.parse(string_uri);
private String[] projection={SearchManager.SUGGEST_COLUMN_QUERY};
.....
cursor=getContentResolver().query(uri,projection,null,null,null);
search_history_list=(ListView)findViewById(R.id.search_history_list);
simpleCursorAdapter=new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1,cursor,
new String[] { SearchManager.SUGGEST_COLUMN_QUERY },new int[]{android.R.id.text1},SearchManager.FLAG_QUERY_REFINEMENT);
search_history_list.setAdapter(simpleCursorAdapter);
和定製搜索服務提供商擴展SearchRecentSuggestionsProvider
public class MusicSearchProvider extends SearchRecentSuggestionsProvider {
public MusicSearchProvider() {
setupSuggestions("com.xyz.music_search_provider",DATABASE_MODE_QUERIES|DATABASE_MODE_2LINES);
}
}
的問題是,當運行時,錯誤顯示
cursor=getContentResolver().query(uri,projection,null,null,null);
Caused by: java.lang.NullPointerException: Attempt to read from null array
變了樣下面,
cursor=getContentResolver().query(uri,null,null,null,null);
錯誤是一樣的。 但像變化,
cursor=getContentResolver().query(uri,null,null,new String[]{query},null);
沒有錯誤的表現,但結果只有一個是顯示在列表視圖。 任何人都知道爲什麼以及如何解決這個問題,請幫助我。