Eclipse not Recognizing “R.id…” with Android

2020-07-08 07:48发布

Any ideas why at times Eclipse frizzles and doesn't recognize code it did seconds ago? The "R" in the code below has the red squiggle under it when it didn't 5 minutes ago and I've change no code. This happens frequently with Eclipse and usually I shut it down and start it again and it's good to go...no go this time.

// Initialize view elements
    mSearchBox      = (EditText) this.findViewById(R.id.edittext_search);
    mSearchButton   = (Button) this.findViewById(R.id.button_search);

8条回答
家丑人穷心不美
2楼-- · 2020-07-08 08:15

If you feel that your code is correct and you still get this error then.

Right Click on Project >> Build Project and this error will go off.

You can also keep a setting where a project is built automatically

Click on Project Tab >> Build Automatically.

Hope this solves your problem!!

查看更多
Evening l夕情丶
3楼-- · 2020-07-08 08:16

did you accidentally import android.R.*; by any chance? I imported this one and that makes eclipse not recognize all the other generated R classes, make sure you are importing the one from your project:

import <project_name>.R;
查看更多
登录 后发表回答