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);
}
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.