Reputation: 21
i have created these button but getting the error of "error: id cannot be resolved or is not a field" in every line of(// buttons) and "error: layour cannot be resolved or is not a field" of (r.layou.main) hwever dont see any errors my layout keypad.xml
keypad.Java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Buttons
one= (Button) findViewById(R.id.keypad_1);
two= (Button) findViewById(R.id.keypad_2);
three= (Button) findViewById(R.id.keypad_3);
four= (Button) findViewById(R.id.keypad_4);
five = (Button) findViewById(R.id.keypad_5);
six= (Button) findViewById(R.id.keypad_6);
seven = (Button) findViewById(R.id.keypad_7);
eight = (Button) findViewById(R.id.keypad_8);
nine = (Button) findViewById(R.id.keypad_9);
minus = (Button) findViewById(R.id.keypad_subtract);
hash = (Button) findViewById(R.id.keypad_hash);
keypad.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/Title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:textSize="45sp">
</TextView>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keypad"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*" >
//setting up keypad buttons one, two and three in one row
<TableRow>
<Button android:id="@+id/keypad_1"
android:text="@string/keypad_1" >
</Button>
<Button android:id="@+id/keypad_2"
android:text="@string/keypad_2" >
</Button>
<Button android:id="@+id/keypad_3"
android:text="@string/keypad_3" >
</Button>
</TableRow>
//setting up keypad buttons 4,5 and 6 in second row
<TableRow>
<Button android:id="@+id/keypad_4"
android:text="@string/keypad_4" >
</Button>
<Button android:id="@+id/keypad_5"
android:text="@string/keypad_5" >
</Button>
<Button android:id="@+id/keypad_6"
android:text="@string/keypad_6" >
</Button>
</TableRow>
//setting up keypad buttons 7,8 and 9 in third row
<TableRow>
<Button android:id="@+id/keypad_7"
android:text="@string/keypad_7" >
</Button>
<Button android:id="@+id/keypad_8"
android:text="@string/keypad_8" >
</Button>
<Button android:id="@+id/keypad_9"
android:text="@string/keypad_9" >
</Button>
</TableRow>
//setting up keypad buttons del,0,# and - in forth row
<TableRow>
<Button android:id="@+id/delete"
android:text="@string/keypad_DEL" >
</Button>
<Button android:id="@+id/keypad_0"
android:text="@string/keypad_0" >
</Button>
<Button android:id="@+id/keypad_hash"
android:text="@string/keypad_#" >
</Button>
<Button android:id="@+id/keypad_subtract"
android:text="@string/keypad_-" >
</Button>
</TableRow>
</TableLayout>
<TextView
android:id="@+id/incorrect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/incorrect" />
</LinearLayout>
Upvotes: 0
Views: 2805
Reputation: 26
You are calling the wrong .xml file for your layout:
setContentView(R.layout.main);
should be:
setContentView(R.layout.keypad);
also, are you creating the buttons above your onCreate method before you tie them to an id?
private Button one;
private Button two;
// and the rest of them...
Upvotes: 0
Reputation: 111
Is it possible that this error occurs because you have named string and id the same?
Upvotes: 1
Reputation: 66637
It seems project is not compiled yet. Clean your project by right click on project. If no compilation errors(red marks) in xml, clean should resolve the issue.
Upvotes: 1