title: Android: SimpleCursorAdapter & ListView
body: <p>Hi I started programming a ToDo-List on android (in eclipse) which synchronises with Google Tasks and add tasks from your Google Account.
  I implemented a really simple database (according to this tutorial: <a href="http://www.vogella.de/articles/AndroidSQLite/article.html" rel="nofollow">SQLITE Tutorial</a>).
  The project contains one activity, which only implements a listView and a button which allows it to add tasks.(parent activity)
  By clicking the button a new acitvity is started via "startActivityForResult" and you can enter a name and a category.(child activity)
  Then this two strings are passed to the parent activity and added to the database, which is initialized in the parent activity
  Now, the listview should be created and a simpleCursorAdapter should be set; thats the point where the app crashes, on the emulator and on my android handy.
  Heres a code snippet of the start activity:</p>
  
  <pre><code> @Override
  public void onCreate(Bundle savedInstanceState) 
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      initDB();
      initUI();
  }
  
  public void initUI()
  {
      Log.w(TAG, "initUI()");
      populateToDoList();
  
      listView = (ListView) findViewById(R.id.tasklist);
      addButton = (Button) findViewById(R.id.addTask);
  
      addButton.setOnClickListener(new OnClickListener()
      {
  
          @Override
          public void onClick(View arg0) 
          {
              // TODO Auto-generated method stub
              Intent i = new Intent(RememberMe.this, AddTask.class);
              startActivityForResult(i, REQUEST_CODE);
      }   });
  }
  
  public void initDB()
  {
      toDoDBAdapter = new ToDoDBAdapter(RememberMe.this);
      toDoDBAdapter.open();
  }
  
  private void populateToDoList() 
  {
  
      Log.w(TAG, "populateToDoList()");
  
      dbCursor = toDoDBAdapter.getAllToDoItemsCursor();
      Log.w(TAG, "getAllToDoItemsCursor()");
  
      startManagingCursor(dbCursor);
      Log.w(TAG, "startManagingCursor()");
  
      String [] columns = { ToDoDBAdapter.KEY_NAME};
      int [] to = { android.R.id.text1 };
      Log.w(TAG, "Sring from int to");
  
      simpleCursor = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, dbCursor, columns, to);
      Log.w(TAG, "new SimpleCursorAdapter()");
  
      listView.setAdapter(simpleCursor);
      Log.w(TAG, "setAdapter()");
  
      simpleCursor.notifyDataSetChanged();    
  
  }
  
  private void updateList() 
  {
  
      dbCursor.requery();
      simpleCursor.notifyDataSetChanged();
  
  }
  
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data)
  {
      if(resultCode == REQUEST_CODE)
      {
          String taskName = data.getStringExtra("taskName");
          String taskCategory = data.getStringExtra("taskCategory");
  
          toDoDBAdapter.createTask(taskName, taskCategory);
  
          updateList();
  
          Toast.makeText(this, "Aufgabe hinzugefügt", Toast.LENGTH_LONG).show();
      }
  }
  
  @Override
  public void onDestroy() 
  {
      super.onDestroy();
      toDoDBAdapter.close();
  }
  }
  </code></pre>
  
  <p>It stops at </p>
  
  <pre><code>listView.setAdapter(simpleCursor);
  Log.w(TAG, "setAdapter()");
  </code></pre>
  
  <p>I've no idea why or what's the problem; I read that there are problems with the emulator on a 64-bit system but the code doens't work either on my handy and implementing listviews and setting a simpleCursor should not be so tricky O.o
  Heres the logcat:
  <a href="http://dl.dropbox.com/u/37133270/logcat.txt" rel="nofollow">LogCat</a></p>