Android App Troubleshooting: Error Message — R Cannot be Resolved - dummies

Android App Troubleshooting: Error Message — R Cannot be Resolved

By Barry Burd

Every Android app has an R.java file. The Android development tools generate this file automatically, so normally you don’t have to worry about R.java. Occasionally, the file takes longer than average to be generated. In this case, Eclipse finds references to the R class in the rest of the project’s code and complains that the project has no R class. Just wait.

If one minute of waiting doesn’t bring good results, follow these steps to double-check the project settings:

  1. Highlight the project in the Package Explorer in Eclipse.

  2. From the main menu, choose Project.

    A list of submenu items appears.

  3. Look for a check mark next to the Build Automatically menu subitem.

  4. If you don’t see a check mark, select the Build Automatically subitem to add one.

    With any luck, the R.java file appears almost immediately.

If the project is set to Build Automatically and you still don’t have an R.java file, try these steps:

  1. Highlight the project in the Package Explorer.

  2. From the main menu, choose Project.

    A list of submenu items appears.

  3. In the Clean dialog box in Eclipse, select the project that’s giving you trouble along with the Clean Projects Selected Below radio button.

  4. Click OK.

Cleaning the project should fix the problem. But if the problem persists, close Eclipse and then restart it. (Eclipse occasionally becomes “confused” and has to be restarted.)

After copying Java code from one Android project to another, you might see the annoying message Import cannot be resolved near the top of the program. If so, you might have inadvertently told one project to fetch material from another project’s R.java file. If the offending line of code is import somethingOrOther.R, try deleting that line of code. Who knows? Your deletion might just fix the problem.