【问题标题】:Problem using Cursor to populate a spinner使用光标填充微调器的问题
【发布时间】:2011-09-16 14:00:41
【问题描述】:

我在使用 SQLite 数据库中的数据填充微调器时遇到问题。这是我的活动中的代码。 Activity 崩溃并出现 Unable to start Activity ComponentInfo 错误,箭头指示。

public class ProjectsActivity extends Activity {

private ReelDbAdapter dbHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.projects_select);

    fillProjectSpinner();

}

private void fillProjectSpinner(){
    // initialize cursor to manage data binding to spinner

    Cursor projectCursor = null;
    Spinner spnExistingProjects = (Spinner)findViewById(R.id.spnExistingProject);

--->    projectCursor = dbHelper.getExistingProjects();

    //startManagingCursor(projectCursor);
    /*
    //get the list of project names from the database
    String[] from = new String[] {dbHelper.clmProjectName};
    //add a new item to the spinner for each of the rows in the database
    int [] to = new int[]{R.id.txtViewProjectRow};

    //initialize a cursor adapter (similar to ArrayAdapter when populating a spinner from a pre-defined array)
    SimpleCursorAdapter projectAdapter = new SimpleCursorAdapter(this, R.layout.view_project_row, projectCursor, from, to);
    //add all the rows to the spinner
    spnExistingProjects.setAdapter(projectAdapter);
    */
}

这是来自我的 dbAdapter 的 getExistingProjects 方法的代码 公共游标 getExistingProjects() {

    if(mDb == null)
    {
        this.open();
    }

    return mDb.query(dbTableProject, new String[] {clmProjectName, clmProjectShootingTitle, clmProjectJobNumber},
            null, null, null, null, null);
}

关于我可能做错了什么的任何线索? TIA 寻求帮助。 规范

【问题讨论】:

  • 看起来不错,我们需要堆栈跟踪。

标签: android sqlite cursor spinner


【解决方案1】:

为什么不尝试在方法中返回光标之前确保查询返回某些内容?放一个日志行,吐出游标的计数。此外,您应该能够在使用调试器单步执行时轻松看到这一点。

另外,为什么要在几行下初始化光标的减速时为它分配 null。一行完成所有操作。

最后,您要与 this.open() 行合并什么数据库?我显然无法仅凭您发布的代码来判断,但是尝试围绕整个事情进行尝试并吐出 strackTrace。你应该看到你的问题。

【讨论】:

  • 基于我所做的一些错误捕获,我什至没有进入数据库适配器中的查询。
猜你喜欢
  • 2012-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多