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);
    }
}
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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.