Android :: Why "R" Resource File Is Not Generated?
Oct 17, 2010
Again and again I have the case that during development, the Android SDK suddenly doesn't regenerate the "R" file. Usually this is due to some error in one of the many .xml files, but that darn thing doesn't give the slighted indication, as to WHY it suddenly refuses to regenerate that file. There is no error or warning listed for any of my .xml files and manually checking all those (meanwhile almost hundred!) XML files for errors is no real fun, either! Is there some option or log or something that would allow to locate the problem quicker and more direct? Last time I had to do a lengthy binary search (i.e. copying and removing files to/from a second test project) trying to locate the offending file. That's really a nightmare and not how it should be in any decent SDK that deserves that name!
I have an XML resource file: <resources> <section> <category value="1" resourceId="@xml/categoryData1" /> <category value="2" resourceId="@xml/categoryData2" /> <category value="3" resourceId="@xml/categoryData3" /> </section> </resources> Using XmlPullParser, on the START_TAG, I can use: int value = parser.getAttributeIntValue(null, "value", 0); to get values 1, 2, 3...however: int resourceId = parser.getAttributeIntValue(null, "resourceId", 0); doesn't work...it just yields the default value 0, or whatever I change the default value (3rd parameter) to be. Does anyone know what I am doing wrong or if this is possible?
Building our Android app from Ant fails with this error:
[apply] [apply] UNEXPECTED TOP-LEVEL ERROR: [apply] java.lang.OutOfMemoryError: Java heap space [apply] at java.util.HashMap.<init>(HashMap.java:209) [apply] at java.util.HashSet.<init>(HashSet.java:86) [apply] at com.android.dx.ssa.Dominators.compress(Dominators.java:96) [apply] at com.android.dx.ssa.Dominators.eval(Dominators.java:132) [apply] at com.android.dx.ssa.Dominators.run(Dominators.java:213) [apply] at com.android.dx.ssa.DomFront.run(DomFront.java:84) [apply] at com.android.dx.ssa.SsaConverter.placePhiFunctions(SsaConverter.java:265) [apply] at com.android.dx.ssa.SsaConverter.convertToSsaMethod(SsaConverter.java:51) [apply] at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:100) [apply] at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:74) [apply] at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:269) [apply] at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:131) [apply] at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:85) [apply] at com.android.dx.command.dexer.Main.processClass(Main.java:297) [apply] at com.android.dx.command.dexer.Main.processFileBytes(Main.java:276) [apply] at com.android.dx.command.dexer.Main.access$100(Main.java:56) [apply] at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:228) [apply] at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245) [apply] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:130) [apply] at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108) [apply] at com.android.dx.command.dexer.Main.processOne(Main.java:245) [apply] at com.android.dx.command.dexer.Main.processAllFiles(Main.java:183) [apply] at com.android.dx.command.dexer.Main.run(Main.java:139) [apply] at com.android.dx.command.dexer.Main.main(Main.java:120) [apply] at com.android.dx.command.Main.main(Main.java:87)
Ive tried giving Ant more memory by setting ANT_OPTS="-Xms256m -Xmx512m". (This build machine has 1Gb RAM). Do I just need more memory or is there anything else I can try?
I am doing the Notepad tutorial, exercise 2. I started by creating a new Android project and chose Create from source to import the downloaded source files for the excercise. But now I get many errors in Eclipse, and the problem is that there is no generated R.java class. How can I solve this? The folder gen / is empty. I have errors on Notepadv2.java and in res/layout/note_edit.xml and both seems to be related to the fact that the generated R.java is missing. Here is my import statements in Notepadv2.java:
I dont want to hardcode the name of the package or where it lives when building an Android project with ant. Im using the build file generated by Android. What properties contain the output folder (bin) and package name (e.g. package.apk) ?
When I make a new project the .java file is not generated. I can run the project, but it does not run in the emulator or anything. It did use to work before then it stop working. I tried deleting the folder and all project files. After that I reinstalled everything but I am still having problems.
I'm using an ant build file that has been generated by android. Our Android application requires a JAR file that lives inside the lib folder of our project, so I need to adjust the classpath that ant is using when it builds stuff.
When I run:
ant -lib lib debug
the project builds just fine, but this should really be inside the build file itself. The build file that android generates references the android_rules.xml so a lot of this stuff is automated. I guess my question, what the best practice here when working with the Android build rules ?
All of the android examples for XmlPullParser pull from a local resource file, and all of the SAX examples pull the XML from a URL. I've been told SAX is faster, so I'm trying to use that to pull data from a local resource file (res/xml/thefile.xml)
The example code I'm working off of is here. So in that example, the code I want to change is:
URL url = new URL("http://example.com/example.xml"); ... xr.parse(new InputSource(url.openStream()));
Instead of using URL, I want to use getXml(R.xml.thefile) Is that possible, or does SAX need to get data from a URL?
I'm interested in instantiating a LinearLayout object from an xml file that has a LinearLayout file configuration. I want to do this within a method of my Activity. I tried findViewById() but that returned null. I've made sure that the LinearLayout id is the one I'm passing. Note that this layout isn't part of my screen, it's stand-alone, so I want to build a LinearLayout object from the xml.
I am trying to read a file "words.txt" from a resource. It is a very simple, but large (2 MB), text file that I want to read line by line. I have put the file into /res/raw/words.txt, and try to open it with the following code:
However, I get a java.io.IOException. This is not a "resource not found" exception, so the resource is opened correctly, but the readLine() produces the error.
I tried using the InputStream itself, with the result that read() produces -1, which stands for EOF, as if the file was empty.
I have a text file added as a raw resource. The text file contains text like:
a) IF APPLICABLE LAW REQUIRES ANY WARRANTIES WITH RESPECT TO THE SOFTWARE, ALL SUCH WARRANTIES ARE LIMITED IN DURATION TO NINETY (90) DAYS FROM THE DATE OF DELIVERY.
b) NO ORAL OR WRITTEN INFORMATION OR ADVICE GIVEN BY VIRTUAL ORIENTEERING, ITS DEALERS, DISTRIBUTORS, AGENTS OR EMPLOYEES SHALL CREATE A WARRANTY OR IN ANY WAY INCREASE THE SCOPE OF ANY WARRANTY PROVIDED HEREIN.
c) (USA only) SOME STATES DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT APPLY TO YOU. THIS WARRANTY GIVES YOU SPECIFIC LEGAL RIGHTS AND YOU MAY ALSO HAVE OTHER LEGAL RIGHTS THAT VARY FROM STATE TO STATE.
On my screen I have a layout like this:
The code to read the raw resource is:
The text get's showed but after each line I get a strange character  How can I remove that character ? I think it's New Line.
I am trying to get a video to pop up and play. I can get it to work when I use the first uri (that is commented out in the below code), but when I try to use the second uri (from the resource), I get the following error:
From researching the error, it looks like I might have to declare an activity in the manifest but I'm not sure if that applies here?? Can someone point me in the right direction?
I use this method couples of occasion to load text file to display as help file. But I don't know why the following code didn't work. It seems to hang and logcat says "OutOfMemoryError"? All I did was break this out as an separate activity.
I'm trying to unbundle a binary file (sound1.ogg) and store it on the sdcard.So it starts out as a raw resource (R.raw.sound1) and should end up as a copy named /sdcard/ mydir/sound1.ogg I wrote a method called something like copyResourceToFile() and did a copy via file descriptors / streams. But the target file just isn't right.If I do a buffered read, the target file ends up being WAY bigger - like 10x bigger.If I just do a byte-by-byte read for the size of the original file, the target file is the right size but is not the same file. Is there a simpler (well, correct/working) way to do this thing?
Is is possible to specify data in xml resource file and initialize ArrayList from it? I am looking for a way to use the ArrayList with a SimpleAdapter to bind to a ListView. I am wondering if there is a way to specify my data in xml resource file and init ArrayList from it.
My 1.6 app works fine in both portrait and landscape modes on the default HVGA device. I'm now trying to support it on QVGA devices and am encountering build-time errors I don't understand. In my res/drawable-ldpi directory I have:
startstopin.png startstopout.png and a selector file startstopbuttonimageselector.xml which contains: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable-ldpi/startstopin" /> <!-- pressed --> <item android:drawable="@drawable-ldpi/startstopout" /> <!-- default --> </selector>
I've 'fixed project properties' and done a 'clean' build, to no avail. The error I get is: Error: No resource found that matches the given name (at 'drawable' with value '@drawable-ldpi/startstopin'). Error: No resource found that matches the given name (at 'drawable' with value '@drawable-ldpi/startstopout'). I've tried adding a layout file in res/layout-small that explicitly references this selector file, but this triggers a similar build error and fails to address the original problem: Error: No resource found that matches the given name (at 'src' with value '@drawable-ldpi/startstopbuttonimageselector').
I generated a new android project in eclipse. I then copied all the files from chapter 3 in my book over to the project. After doing so the R.anything is not available and the resource file is missing. I try to clean the project and generate it but it isn't working. What I can do to fix this error?
The automatic generation of the R class does not work anymore. I have tried Project -> Clean.A warning on all xml files has also showed up: No grammar constraints (DTD or XML schema) detected for the document." Maybe that is why the code generation have stopped. Any idea how to get the R class generated again?
I've been working on a project for several weeks now, and just tonight I started having a problem. The R.java file is no longer being generated. I've attempted to clean the project (the first time I do this it removes the R.java file but doesn't regenerate it) and have tried uninstalling and reinstalling the SDK. I've also tried resetting adb to no avail.
This problem does not occur in my other Android projects. They clean just fine and regenerate the R.java file like nothing is wrong. This particular project is the only one suffering from this problem.
I am currently working on a project which requires me to use an XML document to render a form on an Android device. The form must be fetched and displayed at run-time. I am wondering if there is a way to tag the form XML, transform it using XSLT into an Android layout XML, and then have the device render it.