Tag: xml

When Eclipse won’t generate/locate R.java

I’ve just come across a rather irritating habit of the ADT toolset for Eclipse and thought I’d share it.

If you get a red line under “R” in a reference to a layout, string or id, (e.g. the “R” in R.layout.main) then your problem could be one of the following:

  • You have ‘android.R’ as an import in your java class. This should not be there, remove it
  • You need to ‘clean’ your project by going to Project > Clean on the Eclipse menu bar
  • You do not have Eclipse set to ‘Build Automatically’. Do this by going to Project in the menu bar and ticking ‘Build Automatically’

My problem, however, was none of these. Eclipse just refused to generate R.java.

It turns out that if you have any errors in your xml files (strings.xml, layouts, etc.), then your R.java file will not be generated and you will not be told this is the reason.

Make sure any errors in your xml files are fixed and your R.java file should be generated automatically when you save.

How to change the refresh rate/interval of AdMob ads on Android

Once you’ve set up AdMob ads for your application, you might want to change how often they are refreshed.

If they are refreshed often, your users will see more ads when they’re on the same screen. This is good in that they see more ads, but can also be very annoying.

In the XML entry for your AdMob banner, just add this attribute to set your refresh rate to 60 seconds, as an example:

AdMob only allows you to have a refresh rate between 12-120 seconds

The complete XML element for the AdMob banner should look something like this: