R errors in eclipse

+1 vote

I have the following code:

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<Comment> values = datasource.getAllComments();

    // use the SimpleCursorAdapter to show the
    // elements in a ListView
    ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(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<Comment> adapter = (ArrayAdapter<Comment>) 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() > 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();
  }

} 

I'm getting the following three errors:

setContentView(R.layout.main); 
                         ^
                      main cannot be resolved or is not a field
case R.id.add:
           ^
        add cannot be resolved or is not a field
case R.id.delete:
           ^
        delete cannot be resolved or is not a field
Nov 8, 2018 in Data Analytics by Ali
• 11,360 points
720 views

1 answer to this question.

0 votes

remove import android.R

Then clean and rebuild project. R will be generated.

answered Nov 8, 2018 by Maverick
• 10,840 points

Related Questions In Data Analytics

+1 vote
1 answer

what causes these cannot open errors in R?

They are caused by attempts to read a ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 52,360 points
498 views
0 votes
1 answer

how to run a logistic regression with clustered standard errors in R?

have a look at rms package. lrm is logistic ...READ MORE

answered Nov 6, 2018 in Data Analytics by Kalgi
• 52,360 points
1,504 views
0 votes
1 answer

How do I check and catch errors in R

With tryCatch you can handle errors as you want: an.error.occured ...READ MORE

answered Nov 6, 2018 in Data Analytics by Kalgi
• 52,360 points
447 views
0 votes
1 answer

How do I ignore errors in R

With the try function you can handle errors to ...READ MORE

answered Nov 6, 2018 in Data Analytics by Kalgi
• 52,360 points
10,148 views
0 votes
1 answer
0 votes
1 answer

Errors on eclipse console as soon as I create a new activity

Restart your eclipse might be solve this ...READ MORE

answered Nov 8, 2018 in Data Analytics by Maverick
• 10,840 points
359 views
+1 vote
2 answers

Error saying "R cannot be resolved" Android Error

Also check this out: https://www.edureka.co/community/29897/saying-ca ...READ MORE

answered Dec 12, 2018 in Data Analytics by Maverick
• 10,840 points
492 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
2,016 views
+1 vote
1 answer

How to give line numbers in errors in R?

Use the following command: options(show.error.locations = TRUE) READ MORE

answered Nov 8, 2018 in Data Analytics by Maverick
• 10,840 points
691 views
0 votes
1 answer

Creating barplot with standard errors plotted in R

For df1 plot # Group data by when ...READ MORE

answered Nov 12, 2018 in Data Analytics by Maverick
• 10,840 points
898 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP