Java 使用contentprovider的布尔方法始终返回true?

Java 使用contentprovider的布尔方法始终返回true?,java,android,string,Java,Android,String,我使用以下方法检查数据库中是否已经存在输入字符串: public boolean check(String s){ boolean t = false; ContentResolver contentResolver = this.getContentResolver(); Cursor cursor = contentResolver.query(FTagsContentProvider.CONTENT_URI,

我使用以下方法检查数据库中是否已经存在输入字符串:

public boolean check(String s){
        boolean t = false;
         ContentResolver contentResolver = this.getContentResolver();  
         Cursor cursor = contentResolver.query(FTagsContentProvider.CONTENT_URI,  
                 new String []{FTagsContentProvider.COL_TEXT}, FTagsContentProvider.COL_TEXT + "=?", new String[]{s}, null);  
         if(cursor != null){
             t = true;
         }
         else{
             t = false;
         }
         cursor.close();
        return t;
        }
但无论我输入一个新字符串还是一个已经存在的字符串,这个方法总是返回“true”

是代码有问题还是contentprovider有问题?

检查cursor.getCount()是否为0。不要检查null。光标可以为空且不为null

if(cursor != null && cursor.getCount() > 0) {
         t = true;
} else{
         t = false;
}
检查cursor.getCount()是否大于0。不要检查null。光标可以为空且不为null

if(cursor != null && cursor.getCount() > 0) {
         t = true;
} else{
         t = false;
}