Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse id cannot be resolved or is not a field

I get this irritating id cannot be resolved or is not a field with R.id only, and not R.layout. When I click on the x it says no suggestions, and it is referencing the field correctly (blue & italic).

I've tried cleaning, building, restarting, deleting R, fixing imports. Nothing works.

Following is my code :

package com.example.helloworld;
import com.example.helloworld.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;


public class NameGetter extends Activity implements OnClickListener 
{
    @Override
    public void onCreate(Bundle b){
        Button btn;
        super.onCreate(b);
        setContentView(R.layout.namegetter);
        btn = (Button) findViewById(R.id.button1);
        if (btn != null){
            btn.setOnClickListener(this);
        }
    }

    @Override
    public void onClick(View v) {

        String name = "";
        Intent i = new Intent(this, MainActivity.class);
        EditText et = (EditText) findViewById(R.id.editText1);
        if (et != null){
            name = et.getText().toString();
        }
        i.putExtra("n", name);
        this.startActivity(i);
    }
}

How can I determine the source of this error?

like image 869
Abdou23 Avatar asked Mar 20 '26 08:03

Abdou23


1 Answers

also: remove "import android.R" from imports at top of file (if there)

like image 117
Maysam Torabi Avatar answered Mar 22 '26 17:03

Maysam Torabi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!