1

I'm having a problem populating my spinner with data from my SQLite database. Here's the code from my Activity. The Activity crashes with an Unable to start Activity ComponentInfo error where indicated with an arrow.

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);
    */
}

Here's the code from the getExistingProjects method from my dbAdapter public Cursor getExistingProjects() {

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

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

Any clues on what I might be doing wrong? TIA for any help. Norm

1
  • Doesn't look bad, we need the stack trace.
    – Snicolas
    Jun 16, 2011 at 17:38

1 Answer 1

0

Why don't you try making sure the query is returning something before returning the cursor in your method? Put a log line in that spits out the count of the cursor. Also, you should be able to see this easily while stepping through with the debugger.

Also, why assign null to the cursor's deceleration when you're just going to initialize it a few lines down. Do it all in one line.

Lastly, what db are you trying to one with that this.open() line? I obviously can't tell with just the code you've posted, but put a try catch around that whole thing and spit out the strackTrace. You should see your issue.

1
  • Based on some error-trapping I did, I'm not even getting to the query in the database adapter. Jun 16, 2011 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.