1

I am trying to set a icon variable so that I can use it within my library fragment.

The icons ive put in the drawable folders...

When I try the following it does not work?

 private final static int ICON_FOLDER = R.drawable.ic_folder;

Says cannot resolve R? I even tried to import the library R however this was not possible? Ive tried clean and rebuild (which usually fixes it) and no luck.

It is strange as to why it is not working ive never had this issue and the internet doesnt seem to have an answer as to what im doing, which is to use the resource of the library within the library itself.

UPDATE 1.0____________________________________

Strangely my application (which is using the library currently) is showing error on R as well... i just did another rebuild & clean no luck though!

UPDATE 2.0 ___________________________________

All my R is now displaying errors? maybe this is a SDK issue?

UPDATE 3.0 ___________________________________

So the reason my main app was not working was that it was missing the build folder with the generated r etc, i just copied it from a backup and now that works

UPDATE 4.0 ___________________________________

**Still cannot use R within the library, may this be caused by r being in my main app and a library cannot depend on a normal project? would this be the case? I am not too sure? Because I can reference my icon within the app but not within the library.

UPDATE 5.0 __________________________________

There is an issue with my library, as in the library android documentation "source code in the library module can access its own resources through its R class."

Kurdish Droid
  • 279
  • 3
  • 15
  • Android Studio or eclipse? – weston Mar 14 '15 at 18:24
  • Android studio, I just checked the SDK and it seems fine? any way of checking? – Kurdish Droid Mar 14 '15 at 18:30
  • You said it worked yesterday, look at your changes in source control one of those changes has broken it. – weston Mar 14 '15 at 18:33
  • You do need to import `R`, and as `R` is generated, you must not have any other build errors. – weston Mar 14 '15 at 18:35
  • how can I find this? when I started this afternoon it gave me an error with SDK? however i didnt notice what it said, I just thought it was that it was going to use default SDK. Any way to check this before I go any further? – Kurdish Droid Mar 14 '15 at 18:35
  • just tried to import R however it now gives me an error on my activity_main (this is crazy it has no errors it has never had any issues why now?) – Kurdish Droid Mar 14 '15 at 18:37
  • So, I'm guessing no source control. Try a new project, if that works, your environment is OK. – weston Mar 14 '15 at 18:38
  • it works fine, the only thing that I can think off that may have caused this is that I removed the extends ActionBarActivity and changed to Activity.. this should not cause this issue? now I try to revert it back and it gives me errors saying that it cannot resolve symbol. – Kurdish Droid Mar 14 '15 at 18:44
  • So the reason my main app was not working was that it was missing the build folder with the generated r etc, i just copied it from a backup and now that works.________________________ still issue with library class using library resource. – Kurdish Droid Mar 14 '15 at 19:26
  • @weston Please see above under update 4, any suggestions how to procced# – Kurdish Droid Mar 14 '15 at 19:35
  • have tried that many times, still the same issue. – Kurdish Droid Mar 15 '15 at 12:48
  • possible duplicate of [R cannot be resolved - Android error](http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error) – Marcus Mar 15 '15 at 12:54
  • @Marcus I tried to find my answer there with no luck but I have answered my own question now, it was due to corrupt "build" folder. – Kurdish Droid Mar 15 '15 at 12:56

2 Answers2

0

You should be able to access your items in the drawable folder with:

public static int Whatever = android.R.drawable...
eatyourpeas
  • 117
  • 2
  • 5
  • Yestwerday this was working on my main app... setContentView(R.layout.activity_main); not sure why R is not working? – Kurdish Droid Mar 14 '15 at 18:13
  • And yeah ive tried that before but it doesnt seem to recognize the icon name? – Kurdish Droid Mar 14 '15 at 18:15
  • "Yestwerday this was working on my main app" Sanity check - check your code out as it was yesterday. It will show if the environment is the problem or the code. – weston Mar 14 '15 at 18:28
0

Finally figured it out! Both the Build folders of my application as well as the library must have been corrupt or missing as replacing it with backups of this folder fixed all the problems, I am guessing r - the generated file must have been defected.

Kurdish Droid
  • 279
  • 3
  • 15