Why are my resources suddenly unresolved in my And

2019-02-20 19:02发布

Eclipse is complaining about my Android project saying all my references to resources are unresolved, even though R.java does exist. For example:

signin_btn=(Button)findViewById(R.id.signin_btn); signin_btn.setOnClickListener(this);

I definately have signin_btn defined in my resources. Dont know why Eclipse is not seeing my R class anymore. How to fix?

2条回答
闹够了就滚
2楼-- · 2019-02-20 19:55

The thing that happens to me once in a while is that Eclipse decides to "help" me by adding the following statement to the top of the source file:

import android.R;

This means that all non-absolute references will now be matched against the Android built-in resources, instead of your own. Something like "R.id.layout" is now supposed to be in "android.R.id.layout" and not in "com.mydomain.myproject.R.id.layout". Just remove the line.

查看更多
你好瞎i
3楼-- · 2019-02-20 19:57

It happens to me, this is what I think happens:

Whatever process generates R.java starts at the top of your resources and works to the bottom. If it encounters an error somewhere, it just stops... leaving whatever resources haven't been added to R.java out. This is why some of them will say "unresolved", and others will be fine.

It seems that every time you save a file in your project, it regenerates R.java (maybe it's just the files in res/), so you probably fixed whatever the generator broke on, and when you saved AndroidManifest.xml, it regenerated R.java.

查看更多
登录 后发表回答