Assigning ids to few edit texts results in the following error :
the error is in the parameters of findViewById token
Here is the line of code that its on
final EditText myEditField = (EditText) findViewById(R.id.percentText1);
…This is the Xml code sorry again to nerd for posting the java…
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/percentText1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/enterButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="224dp"
android:onClick="onEnterClick"
android:text="Calculate Tip" />
<EditText
android:id="@+id/percentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="53dp"
android:ems="10"
android:singleLine="true"
android:text="Percent" />
<EditText
android:id="@+id/percentage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/percentText"
android:layout_alignParentTop="true"
android:ems="10"
android:singleLine="true"
android:text="Bill Amount" >
<requestFocus />
</EditText>
</RelativeLayout>
…The Java Code… The error i figure is that i improperly gave the edit text an id…
package tip.calculator;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import tip.calculator.R;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText myEditField = (EditText) findViewById(R.id.percentText); //error here
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onEnterClick(String args []){
int percentage;
int percentageInp;
int billAmount;
}
}
Make sure that you dont have this in your imports
Eclipse sometimes imports this class which instead should be
usually this happens when we
ctrl+shft+oto fix imports. Eclipse adds theRclass when we do that. 🙂EDIT:
from your new question, there is a spelling error.
Try to paste this line inside the onCreate() method: