I have no access to images from code (R.drawable ...) - java

I'm working on an Android game with Eclipse, suddenly appears lots of errors in the code. Eclipse now don't recognize R.drawable resources ....
Console shows the following warning:
libpng warning: Ignoring gAMA chunk with gamma=0
What can I do to continue as it was?

I found the solution. seems there was an error in the import of the R file (resources file).
I replaced
import android.R
for
import package.name.R
Thanks for the help

I'm definetly not the most advanced guy out here but I have lost my R.java file more than a couple of times. You lose the whole thing whenever there is one thing that should be added but has an error. So almost all of those errors that you are seeing are secondary errors. Did you add an image or some other type of resource that you can think of when you lost your r.java?

Did you try Cleaning and Building the project? Go to Project > Clean and clean your project. Then try running it again. Most of the time when I see problems with my R.java a clean and build will fix it.
If that doesn't help, can you paste your code or a sampling of it?

Related

IntelliJ can't find classes in same package when compiling

As an extension to my previous question (IntelliJ can't find depencency when compiling, but can in editor.) which got solved, I now have a new issue which has sprung up.
Within the same packages, references to other classes are showing up with errors:
As you can see in the picture, there is happening at the line involving the BifCreatorController, even though that class is in the same package as the BifCreatorView.
Just like my previous question, I am failing to understand why IntellJ is spitting out those errors. This project works just fine in Eclipse, but I am looking to start moving away from eclipse.
Got same problem today. Rebuilding or restarting both didn't work for me. In the end, I tried to rename the class, problem solved! Then I rename the class to the name I want, everthing was fine!
This is because BifCreatorController is excluded from compilation (see the small "X" top-left icon near to the file name). One reason would be the file got some errors while compiling, IDEA proposed to exclude it from compilation and you had accepted.
Go to "File > Settings > Build, Execution, Deployment > Compiler > Excludes" and remove it from there.
I had the same problem, i cleared the cache and restarted but it did not solve the problem. Then i right clicked the not found class and selected Recompile and after recompilation the problem was solved.
For those who can't beat the trouble i suggest switching to maven because it's predictive:
Maven > Runner > Delegate IDE build/run actions to Maven
Another reason is the cache problem.
Go to -> File -> Invalidate Caches / Restart ...

Cannot find the symbol class R even after adding import com.example.app.R;

I am using IntelliJ IDEA and i tried to build my android application and it was giving an error saying 'Cannot find the symbol class R' at all the places where I used R in the code. I already included 'import com.example.app.R' line in all the classes and the code is all correct and showing no errors. I also checked
File->Project Structure->Modules and both gen and src are included as sources.
Help me fix this.
Could you please try this way
File-> Invalidat Caches/Restart and then click on the Invalidate and Restart button.
Sometimes, it takes from the cache and screws up the operation, restarting and invalidating cache mostly works, please try out and inform.

R.java is not created

I've found out that my R.java is never created. I'm using Android Studio and rebuilding does not solve the problem as well.
As far as i can see i don't have any mistakes in my XMLfiles as well.
I'm using W7. The error cannot resolve symbol R resolves.
Please help!
Code can be found here
I have created a new project and copy-pasted your code and it works fine (in Intellij IDEA 12 at least). I have dropped the line (this one android:theme="#style/AppTheme") with theme because you haven't provided code for your theme.
If you haven't added any gfx or other files and you're absolutely sure about the correctness of you theme style, then try to create a new project and do the same I did - code copy & paste.
If you have an error on your any code. No clean/build works to build R.java.
Just check your whole codes fix errors manually (Because of R.java is not builded it will show errors everywhere. So you have to find and fix errors on your own.)
It's usually due to an unaccepted character in the resources names, check for dashes, spaces and caps and let the project refresh

R.layout.main couldn't be resolved

I am building an application and I added a new activity to generate a view. I compiled it. My application can not find anything that is on the format R.id.xxx or R.layout.xxx, I've tried also cleaning my project, closing Eclipse and opening Eclipse again, but nothing. The most strange thing is that before everything was working well. But now it can not recognize even the R.layout.main that is default of my principal activity. Anyone have an idea?
Also I have tried almost everything here: R cannot be resolved - Android error
but no result!
Solved
Thanks to woopsy, also I found the reference to this kind of problem
http://source.android.com/source/using-eclipse.html
it happens because Eclipse sometimes imports R when you press the combination ctrl+shift+O
Remove all your imports for the Activity and then have eclipse fix imports. I have had problems where eclipse wants to import a different R than the one I need.
First of All Check You have R.java File then check
import android.R;
Enter Yourpackages like import com.mypackages.prj;
If you are using eclipse, take a backup of your layout main.xml file and then from the eclipse new file interface create a new "Android XML File" and call it main.xml. copy back from the backup the contents into this new file.
try this.
check your xml files. there might be something wrong in it which is causing R not to build up automatically. To observe such errors, switch your view to Console tab
this is a common error. You need to just search your R.java file in generated section of your project directory in Eclipse. Need to import if the R.java file into the package then import . R;
I hope it will work for you. It was absolutely worked for me...enjoy programming
friends take care that u haven't imported R class, if you have delete "import android.R". The reason is there are two R things one R.java and R.class and we need the java, where we dont need to import rather than referring it. It worked for me and may be to you too.
I found the solution...For me works it
Poject->Properties->Android->Project Build Target (here choose android4.4 or 5.1.1 Android Open Source Project)->Ok
Project->Build All
This function ...
This problem can fix with this process: -
File---->Invalidate cache/restart.
it will restart your android studio and fix that problem

Error: Unable to fnd class R.java No such file or dir

I keep getting this when trying to start a new project
ERROR: Unable to open class file C:\Users\Levi\Desktop\Android\workspace\Droid1\gen\com\androidbook\droid1\R.java: No such file or directory
I tried changing preferences to alter build path to project, but it still wouldnt work,,,
Is subfolder on desktop a bad place to install Eclipse?
Clean works sometimes and should be tried. I also find that blowing away the gen directory and refreshing will cause it be to rebuilt. Try that as well.
However, sometimes even that doesn't work and I've been forced to remove the project from Eclipse and then re-import it. This, unfortunately, works for me every time if the above has not.
Good luck.
Im also getting that error, running a Project->Clean in Eclipse helps for me.
Project->Clean should certainly fix this (unless your resources won't compile for some seperate reason).
I remember that the first time I ran Eclipse (in mid 2009, can't remember if it was Galileo or Ganymede or whatever) on Windows Vista, it presented several problems that were eventually traced to Eclipse itself being in a directory whose path contained a space...
Usually, the above tips (refresh, clean) work for me. But lately I had a very persistant instance of this error, which was caused by something else:
One of the layout .xml files in res/layout contained a reference to a custom view (org.company.project1.MyView). However, I had changed the package path (org.company.project2.MyView), so the reference had become invalid.
Thus, if everything fails try browsing your layout .xml files for invalid custom element definitions.
Cheers
after spending hours trying to ultimatly discover the issue behind the Class Issue not being found, resolved,or directory not there issue....
sometimes yes the issue is due to a bad binary or xml... as sometime a clean will do the trick or a xml edit will solve the day.. when all else fails.... this may do it..
"create a new workspace"
go into the workspace.... and then
Switch to your old workspace... in the newly formed workspace...
this was my silver bullet. so frustrating to not have a solid answer.
using Version: Helios Service Release 2
Build id: 20110218-0911

Categories