编译错误:"Cursor cannot be resolved to a type"

3

我正在尝试完成记事本练习1。当我创建fillData方法时,出现了一个错误,提示“无法将Cursor解析为类型”。

以下是我的代码:

private void fillData() {
    //get notes from DB and create item list
    Cursor c = mDbHelper.fetchAllNotes();
    startManagingCursor(c);

    String[] from = new String [] { NotesDbAdapter.KEY_TITLE };
    int[] to = new int[] { R.id.text1 };

    SimpleCursorAdapter notes = 
        new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
    setListAdapter(notes);
}

我需要在我的Java文件顶部导入光标类吗?如果是,该怎么做?


1
@xscott import 实际上是一个声明(我曾经一度以为它也是一个语句)。https://dev59.com/PU3Sa4cB1Zd3GeqPwpxG - OscarRyz
@Falmarri 是的,我正在使用Eclipse。 - LuxuryMode
你应该看到 Cursor c 下面有一条小红线,上下文菜单会告诉你该怎么做。 - Falmarri
1个回答

7

很可能您需要添加一个 import 声明

例如:

import android.database.Cursor;

谢谢。我只是让Eclipse自己处理。右键单击错误并导入正确的类。 - LuxuryMode
那个和import android.widget.SimpleCursorAdapter; 显然。 - LuxuryMode
3
如果你正在使用Eclipse,只需按Ctrl+Shift+O导入所有必要的包即可。 - SteD

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接