简体   繁体   中英

Why are my resources suddenly unresolved in my Android project?

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM