0

I am working on a android project using the android sdk and eclipse. I am having problems with my java code so I was wondering if anyone who knows Java can you help me with my code?

Here is my code. These are where im having problems error ->

public class MainActivity extends ActionBarActivity {
 private static final String R = null;
 int counter;
 Button add, sub;
 TextView display;
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
error -> setContentView(R.layout.activity_main);
 counter = 0;
error -> add = (Button) findViewById(R.id.button1);
error -> sub = (Button) findViewById(R.id.button2);
error -> display = (TextView) findViewById(R.id.text);
 add.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 counter++;
 display.setText("Your Total is" + counter);
 }
 });
 sub.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 counter--;
 display.setText("Your total is " + counter);
 }
 });
 }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
 // Inflate the menu; this adds items to the action bar if it is present.
error -> getMenuInflater().inflate(R.menu.main, menu);
 return true;
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
 // Handle action bar item clicks here. The action bar will
 // automatically handle clicks on the Home/Up button, so long
 // as you specify a parent activity in AndroidManifest.xml.`enter code here`
 int id = item.getItemId();
error -> if (id == R.id.action_settings) {
 return true;
 }
 return super.onOptionsItemSelected(item);
 }
}
Robby Cornelissen
98.6k23 gold badges154 silver badges180 bronze badges
asked Jul 12, 2014 at 16:59
1
  • 1
    Please add to the question, what kind of problems you are having. Commented Jul 12, 2014 at 17:18

1 Answer 1

2

Remove private static final String R = null; and add an import for android.R:

import android.R;

You're trying to call methods on the android.R class, but you're not importing it correctly and trying to declare a static field with the same name as a String instead. This makes your compiler sad.

answered Jul 12, 2014 at 17:02
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.