title: R Errors In Eclipse
body: <pre><code>package de.vogella.android.sqlite.first;
  
  import java.util.List;
  import java.util.Random;
  
  import android.R;
  import android.app.ListActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.ArrayAdapter;
  
  public class TestDatabaseActivity extends ListActivity {
    private CommentsDataSource datasource;
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      datasource = new CommentsDataSource(this);
      datasource.open();
  
      List&lt;Comment&gt; values = datasource.getAllComments();
  
      // use the SimpleCursorAdapter to show the
      // elements in a ListView
      ArrayAdapter&lt;Comment&gt; adapter = new ArrayAdapter&lt;Comment&gt;(this,
          android.R.layout.simple_list_item_1, values);
      setListAdapter(adapter);
    }
  
    // Will be called via the onClick attribute
    // of the buttons in main.xml
    public void onClick(View view) {
      @SuppressWarnings("unchecked")
      ArrayAdapter&lt;Comment&gt; adapter = (ArrayAdapter&lt;Comment&gt;) getListAdapter();
      Comment comment = null;
      switch (view.getId()) {
      case R.id.add:
        String[] comments = new String[] { "Cool", "Very nice", "Hate it" };
        int nextInt = new Random().nextInt(3);
        // save the new comment to the database
        comment = datasource.createComment(comments[nextInt]);
        adapter.add(comment);
        break;
      case R.id.delete:
        if (getListAdapter().getCount() &gt; 0) {
          comment = (Comment) getListAdapter().getItem(0);
          datasource.deleteComment(comment);
          adapter.remove(comment);
        }
        break;
      }
      adapter.notifyDataSetChanged();
    }
  
    @Override
    protected void onResume() {
      datasource.open();
      super.onResume();
    }
  
    @Override
    protected void onPause() {
      datasource.close();
      super.onPause();
    }
  
  } 
  </code></pre>
  
  <p></p>
  
  <p>This is my code above.</p>
  
  <p>The three errors that I am receiving are:</p>
  
  <pre><code>setContentView(R.layout.main); 
                           ^
                        main cannot be resolved or is not a field
  </code></pre>
  
  <p>&amp;&amp;&amp;</p>
  
  <pre><code>case R.id.add:
             ^
          add cannot be resolved or is not a field
  </code></pre>
  
  <p>&amp;&amp;&amp;</p>
  
  <pre><code>case R.id.delete:
             ^
          delete cannot be resolved or is not a field
  </code></pre>