Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 可搜索词典示例内容提供程序CursorLeak_Android_Cursor_Android Sqlite_Android Contentprovider - Fatal编程技术网

Android 可搜索词典示例内容提供程序CursorLeak

Android 可搜索词典示例内容提供程序CursorLeak,android,cursor,android-sqlite,android-contentprovider,Android,Cursor,Android Sqlite,Android Contentprovider,我可以知道为什么每次我在搜索管理器中输入内容然后按go时都会出现此错误吗?当我按下GO按钮时,下面的消息总是出现在我的第五次查询中。为什么?根据我从这个链接上读到的 如果我使用的是ContentProvider,则不需要关闭数据库,但为什么我会不断收到此消息?是因为我错过了什么吗 01-20 15:05:34.843: E/CursorLeakDetecter(16689): PossibleCursorLeak:content://com.example.android.searchabled

我可以知道为什么每次我在搜索管理器中输入内容然后按go时都会出现此错误吗?当我按下GO按钮时,下面的消息总是出现在我的第五次查询中。为什么?根据我从这个链接上读到的

如果我使用的是ContentProvider,则不需要关闭数据库,但为什么我会不断收到此消息?是因为我错过了什么吗

01-20 15:05:34.843: E/CursorLeakDetecter(16689): PossibleCursorLeak:content://com.example.android.searchabledict.DictionaryProvider/dictionary,QueryCounter:5
============================================

private void showResults(String query) {

    Cursor cursor = managedQuery(DictionaryProvider.CONTENT_URI, null, null,
                            new String[] {query}, null);

    if (cursor == null) {
        // There are no results
        mTextView.setText(getString(R.string.no_results, new Object[] {query}));
    } else {
        // Display the number of results
        int count = cursor.getCount();
        String countString = getResources().getQuantityString(R.plurals.search_results,
                                count, new Object[] {count, query});
        mTextView.setText(countString);

        // Specify the columns we want to display in the result
        String[] from = new String[] { DictionaryDatabase.KEY_WORD,
                                       DictionaryDatabase.KEY_DEFINITION };

        // Specify the corresponding layout elements where we want the columns to go
        int[] to = new int[] { R.id.word,
                               R.id.definition };

        // Create a simple cursor adapter for the definitions and apply them to the ListView
        SimpleCursorAdapter words = new SimpleCursorAdapter(this,
                                      R.layout.result, cursor, from, to);
        mListView.setAdapter(words);

        // Define the on-click listener for the list items
        mListView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // Build the Intent used to open WordActivity with a specific word Uri
                Intent wordIntent = new Intent(getApplicationContext(), WordActivity.class);
                Uri data = Uri.withAppendedPath(DictionaryProvider.CONTENT_URI,
                                                String.valueOf(id));
                wordIntent.setData(data);
                startActivity(wordIntent);
            }
        });
    }
}
private void showResults(字符串查询){
Cursor Cursor=managedQuery(DictionaryProvider.CONTENT_URI,null,null,
新字符串[]{query},null);
if(游标==null){
//没有结果
setText(getString(R.string.no_results,新对象[]{query}));
}否则{
//显示结果的数量
int count=cursor.getCount();
String countString=getResources().getQuantityString(R.plurals.search\u结果,
计数,新对象[]{count,query});
mTextView.setText(countString);
//指定要在结果中显示的列
String[]from=新字符串[]{DictionaryDatabase.KEY\u单词,
DictionaryDatabase.KEY_DEFINITION};
//指定相应的布局元素,以便将列放在其中
int[]to=新int[]{R.id.word,
R.id.definition};
//为定义创建一个简单的游标适配器,并将其应用于ListView
SimpleCrsorAdapter words=新的SimpleCrsorAdapter(此,
R.layout.result、光标、from、to);
mListView.setAdapter(字);
//为列表项定义单击侦听器
setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
//构建用于打开具有特定单词Uri的WordActivity的意图
Intent-wordIntent=newintent(getApplicationContext(),WordActivity.class);
Uri数据=Uri.withAppendedPath(DictionaryProvider.CONTENT\u Uri,
字符串。valueOf(id));
setData(数据);
startActivity(wordIntent);
}
});
}
}

您有游标泄漏,而不是数据库泄漏嗯,请问是什么原因导致游标泄漏,我应该如何解决?t缺少cursor.close()?我曾尝试在SearchableDictionary.java文件中的私有void showResults(字符串查询)方法中添加cursor.close(),但当我搜索某个内容时,它将显示空列表。是因为我关闭了错误的光标吗?>。<,因为根据searchable dictionary示例,大多数游标方法都是return方法