• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Help me fix this error in code : id cannot be resovled or is not a field

I'm a beginner in android programming.I tried to do a calculator program.But my eclipse is throwing the errors

1) id id cannot be resovled or is not a field in Textfield,textview and for Button. (Line 21,22,23 and 24 in java code)
2)Boolean types not allowed(At numeric with value "true") in main.xml (Line 17,27)
3)Resource id cannot be an empty string ( "at 'id' with value '@+id/' ) in main.xml (Line 17,27)

Somebody please help me in fixing this error.

( I used two editText box for taking two numbers,one textview for displaying the result and a button for starting the addition process.) .

1)My java code is given below:

package com.example.fit;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class fit extends Activity {
Button button1;
EditText txtbox1,txtbox2;
TextView tv;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtbox1= (EditText) findViewById(R.id.txtbox1);
button1 = (Button) findViewById(R.id.button1);
tv = (TextView) findViewById(R.id.lbl1);
txtbox2= (EditText) findViewById(R.id.txtbox2);
button1.setOnClickListener(new clicker());
}
class clicker implements Button.OnClickListener
{
public void onClick(View v)
{
String a,b;
Integer vis;
a = txtbox1.getText().toString();
b = txtbox2.getText().toString();
vis = Integer.parseInt(a)+Integer.parseInt(b);
tv.setText(vis.toString());
}
}
}


2) My main.XML code is given below:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget38"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<Button
android:id="@+id/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_x="40px"
android:layout_y="222px"
>
</Button>
<EditText
android:id="@+id/"
android:layout_width="68px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:numeric="true"
android:layout_x="40px"
android:layout_y="82px"
>
</EditText>
<EditText
android:id="@+id/"
android:layout_width="66px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:numeric="true"
android:layout_x="40px"
android:layout_y="0px"
>
</EditText>
<TextView
android:id="@+id/TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/red"
android:text="TextView"
android:layout_x="40px"
android:layout_y="162px"
>
</TextView>
</AbsoluteLayout>
 
It says perfectly clear what is wrong.

1: You must give each Widget an unique ID if you want to use them in any way in your code, or leave out android:id entirely for the Widget you don't use in your code. You can not give an empty android:id tag, as you have done at both EditText Widgets.
Solution: Give an id, or remove the android:id tag!

2: The numeric tag only takes three types of options, which is: integer, signed and decimal.
Solution: You must give at least one of them, but you can also give more separated by "|" like this:
android:numeric="integer" or android:numeric="integer|decimal"
See here for more: TextView | Android Developers

3: This is together with problem nr. 1. Fix nr.1 and you have fixed this as well.
 
Back
Top Bottom