3

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?

jww
  • 97,681
  • 90
  • 411
  • 885
Abdou23
  • 363
  • 1
  • 4
  • 11

3 Answers3

1

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

Maysam Torabi
  • 3,672
  • 2
  • 28
  • 31
0

Delete "import com.example.helloworld.R;" and then press ctrl+shift+letter "O"

Hope this helps.

Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69
  • Thnx for the help, but it wasn't actually ther, i addedit trying to fix the error. I already tried every common solution. I was hoping for a more out of the box solution. – Abdou23 Mar 05 '14 at 22:32
0

First Clean Your Project and Debug after that id cannot be resolved then check the android Target Version from Project Properties (rite click on project => select Properties =>Select Android) and then check in android sdk Manager (This same version installed or not with correct api) Your Problem will solve