Last night my code was working fine, today when I load it up, the raw resource I access in my code is trying to read from an id pointing to a string rather than an xml file in my raw folder.
I have used http://www.statman.info/conversions/hexadecimal.html to track the resource id's and match them to their R hex id's and I can SEE that it should be accessing 0x7f040002 but is accessing 7f060000 for some reason...
I have already looked at :
Accessing wrong raw resource in Android
I have done all of the following:
Clean, Rebuild, Run.
Delete R, Reboot Eclipse, Clean, Rebuild, Run
Delete R, Clean and Rebuild Immediately, Reboot
UmbySlipKnot's idea of deleting Gen Folder + all of the above.
Making sure Android.R is not being used anywhere.
Printed the actual resource id I am expecting to use by calling (returns expected id correctly!):
int resId=con.getResources().getIdentifier("raw_tsn_xml_amina_simple","raw",con.getPackageName());
Also rebuilt the project entirely from scratch. No matter what I do - it's always getting app name as the resource id it references for the Input Stream - source
None of these have worked for me... Does anyone have any ideas what else I can try?
I have also added images to show you what I noticed:
Debug Snippet:
Android R File Snippet:
I had this issue the other day with the wrong image resource ID being used. The only thing that worked for me was renaming the resource and renaming the references to said resource. So try renaming raw_tsn_xml_amina_simple.xml to something else.
Try removing Gen folder and let it regenerate. Then try again.
Apparently the eclipse debugger is not as dependable as I expected.
While I was working with the debugger, I noticed that resource ID is correctly being found, but when I really nitpick into the debugger, the inputStream seemed to be getting built from another source.
I thought that was the reason my code was crashing, but it wasn't.
I use a SIMPLE xml android library - if the xml you pass it is in an unexpected/invalid format, it can't build the data models you create (My XML was invalid - therefore the crash).
I did a roll back to notice that new XML I had added, crashed the run.
The debugger just cranked out... giving me nulls when things weren't null, showing different values even when my logs were printing correct values!
Once I saw this hapenning, I didn't trust the debugger as much as I ususally do.
My advice :
If the simpler solutions on this page have not worked for you - Take the following steps:
Suspect code additions first! If something you added suddenly breaks your working code, it's probably your own error.
If your debugger acts weird, print useful log information (It is much faster) to give you the right information in the right places.
These are the exact steps I took to find the root of the problem.
Related
k-9-master\k9mail\src\main\res\values\themes.xml:126: error: Error
retrieving parent for item: No resource found that matches the given
name '#android:style/Theme.Holo.Dialog'.
Why am I getting this error?
There are many possible causes of an error. However, if you simply do not see any reason this should be occurring, try a project clean, or simply create a new project and pull over all the files you intended to add to this project.
This is fairly likely to solve your issue as XML files often seem to cause me random problems - i.e. one day it is working, and the next time I open my project (e.g. if put it in different folder and bring it back to same location) it might not be working. I think Eclipse and Android Studio like to edit XML files by themselves sometimes without you knowing about it for some reason unbeknown to me.
hi I'm working in my android app. and suddenly today while I was working I got two errors
1- the "R can't be resolved as a variable" error.
2- and the "Couldn't resolve resource #string/app_name" erro, at the graphical view of .XML layouts.
I did lots of searching and lots of trial and error(clean, build, restart eclipse, restart laptop, and others but none could get me out of this trouble.
I also noticed that My R.Java is gone
I found while I do online searching that R.java could be gone"not auto generated" if there's error with XML or errors such as number 2 error.
last thing which I think might have caused the error is I added two elements in string.xml.. but anyway I have deleted them already.
so could any body help me how to jump this issue and continue with my development
At a guess I'd say that there is something wrong in your resource files which is stopping it from compiling them into the R file.
Take a good look at you string.xml file. The error is almost 100% there .
Have you forgotten to close some tag?
Check that your #string/app_name is well defined too ..
Remove this line: import android.R
note: R.java could be gone not auto generated unless you have no error in project.
now you count replace #string/app_name by "app name" and clean again. after find where have error
In my experience this message is almost always something to do with an error in one of your XML files: could be string.xml, any of your layouts, styles etc.
My advice would be to open up each one of them individually and check through them. An error in the layouts (res/layout/..) should be easy enough to spot (don't forget to check your res/menu/.. also). An error in one of the value XML files (res/values/..) can be tricker to spot. As some of the others have mentioned, a simple error in these files can cause this: one of my most common ones is to have typed "sting" instead of "string" or something similar.
I have often found that even after fixing some of these it is neccessary to close everything down and start Eclipse again.
Just import com.your.packagename.R
See my answer here Cannot find R.layout.activity_main
I am using Eclipse to write my Android app and I keep getting this error when running it. I have no idea what the error means or how to go about debugging.
I should add that this all started when I wrote a method to parse an XML file. Before I wrote that, the app worked fine. I tried adding some try/catch block that contain "log.e" statements, but I don't see anything strange in the log.
Does anyone have any idea?
The error message is in the screen shot below:
It means you don't have the source files of the Android code in you eclipse workspace. check
Android source
By default you only have the compiled class files in you android.jar. if you want to see the source(*.java files) you need to add them yourself. So, you have no source files at all by default
I have had this error come up before for a lot of reasons. Almost always it is because I tried to refer to a resource that either is not there, or is incorrectly formatted. Seeing as how this started when you worked with one of your XML files I would check there for incorrect formatting.
Although this error is referring to the fact that you do not have the full android source code, having it will not fix the error, it will only allow you to see where the source code is failing either to find or open your XML file.
I have an App that was working perfectly, then I released an update and now suddenly some users cannot inflate the main view.. it is dying on inflation of the XML on line 28 with a nested exception of
Resources$NotFoundException: File From Drawable resource ID #0X10200004
on line 28 of the Binary XML inflate which references #drawable/pl
the pl.bmp file is in the res/drawable directory and is not corrupted, so the resource exists.
The only thing I can see that seems odd is the R.java file that is generated references this drawable with an id of #0X7F0200009, and there are no files reference id's that start with #0X1.... at all.. so I am not sure how or why these particular users are even getting that ID as the reference for the drawable. There is an #0X7f0200004 in the R.Java drawable class but it is a completely different graphic.
This is certainly happening with some folks who have upgraded, and I suspect with some folks who have purchased new. I am unable to replicate this behvior on any device I have access to, or on the emulator, but it is clearly happening for some people.
Does anyone have any ideas? Is the upgrade not picking up the right R.java file? How is that even possible? At first I thought it might be a file name collision as earlier releases had p as a bmp and release where this started I changed it to a png, but I made sure to delete pl.bmp before build, and subsequently renamed it to pl, so there is no way even if the old p files both .bmp and .png were somehow on the device it would not possibly collide, but this doesn't seem to be the problem.
Any help would be greately appreciated.
Thanks in advance.
Well this amazingly appears to be something related to an OS Drawable reference tied to the android.R.id.empty.
Don't ask me why this worked fine, and then suddenly started not working for some users after I change my XML definition, but I have removed the reference to this and am now using my own transparent graphic instead and everything appears to be working fine.
I added some UI elements to the main.xml file in the res\layout folder and when I try to access them through the call, R.layout.my_uielement, the UI element that I created is not there. Even when I add a new xml file with UI elements, it still doesn't show up in the R.layout class. I have made checked the ids on them and they have the correct format (I think): android:id="#+id/my_button". What could be the problem? Do I need to compile the code first?
UPDATE:
I have already tried adb kill-server then adb start-server. It doesn't seem to help. I have also tried R.id.my_uielement, it doesn't register either.
This may not be the case for you, but sometimes when I use something from the android.R package (default android resources) and I use it in my class before making reference to anything from my own resource package, Eclipse adds the import android.R; statement in my imports. This will conflict with the default behavior of implicitly looking in your package's resources.
Check your import statements for import Android.R;. If it's there, remove it. And, if you're using anything from android.R, fully qualify it when you use it in code.
Clean project works fine. In Eclipse if you just change some xml components, it doesn't always generate a new R file. Cleaning does it.
Use R.id.your_ui_element, not R.layout.your_element
I faced this problem too. The R.java was neither generated nor updated.
If R.java is not generated when you create the project, run your 'empty` project. An R.java with references to resources will be automatically generated.
If R.java is not getting updated, Check for updates in Help -> Check for Updates
in Eclipse and update your SDK and ADT if required.
After 2 days I found a way to fix it...
I had saved half done project in my mail, so when R.java vanished i just replaced it with the old R.java file, this fixed a lot of errors, then made necessary changes and built the project(build it not clean)...I do not know whether clean and build performs the same job or not..but everytime i cleaned it , R.java used to go invisible...
Clean is working because it BUILD the project after cleaning. So the problem is ( at least it was in my case, because I switched off the Automatic Build a few days earlier ) that after you add an item or anything in a .xml file, the eclipse doesn't build it and can't refresh the R.java .
I've noticed that my R.java file is not always being properly updated when I add items to my strings.xml file or elsewhere. If I use a new value I added like R.string.newString the actual integer value might still be pointing to R.string.oldString or whatever (it seems to usually be the element directly above or below the new element in strings.xml but I haven't nailed down the pattern for sure yet).
You're not supposed to modify the R.java file, but it doesn't say anything about deleting it (not that I've seen, anyway). I've found that deleting R.java usually fixes my resource-related problems because Eclipse immediately regenerates the file with the integer values properly assigned.
Please note, I'm very much a beginner at Eclipse so I may not understand the consequences of deleting R.java but it seems to be working well for me so far. If what I'm doing is very bad, please let me know.
None of these worked for me!
The only way i can access an #+id/foo is by myPackage.R.id.foo.