Showing posts with label Troubleshooting Code. Show all posts
Showing posts with label Troubleshooting Code. Show all posts

Wednesday, June 6, 2012

SOLVED: Project contains R.java error, R.java is missing, R.java not generating


Problem:
1. Eclipse refuses to generate a new .APK, instead generating a popup chiding you for having the gall to include error(s) in your code, as here.
    (X) Your project contains error(s), please fix them before running your application.
2. Your code looks fine. No red stuff anywhere near your files.
3. Travel up the project tree and notice R.java (the automatically generated resource file) is red.

Solution(s):
Basically, Eclipse is telling you there's a problem in a resource file, but it didn't figure this out until you tried to run the code. Follow the red. It's designed to help you locate the source of your pain.

Solution 1:
Be Fearless! Dive into R.java to find the problem. That's right, open it up and look inside. In my case, it was a typographical error (a single tiny tick mark added inadvertently to the end of the text) in the strings.xml file. The offending string was clearly marked in red, so it was trivial to find and fix the typo.

Solution 2:
If  that doesn't get you out of your funk, try this. Technically, it deals with a missing R.java file, but the root cause is very similar.

Solution 3:
Here's another idea to try.

Solutions #2 and #3 were found here.

Solution 4:
Watch this video. There's an example of how to generate (and resolve) a similar condition beginning at frame time 20:32. We highly recommend watching the whole series, published on YouTube. It provides a good introduction to Android programming using Java in Eclipse. Thanks, Marakana, for providing an excellent video of your boot camp training class.


Wednesday, April 18, 2012

TERMINAL TIP: Handy ADB Commands (Android Debug Bridge)

Here are some very useful commands. To use them, you must have installed the Android SDK (Software Development Kit), which includes the command line tool ADB. When you have installed it, you can then open a Windows command window.

adb devices                   lists connected devices
adb [-d | -e] shell           connects terminal mini-bash shell to device (-d) or emulator (-e)





Once in the debug shell, try these commands

kill-server                cuts connection to emulator

start-server              [re-]connects eclipse to emulator

logcat                      displays running log in a terminal windows
logcat TAG:* *:S   filtered: TAG:* = only show all TAG entries; *:S = all others Silent
                                   [ TAG corresponds to Log.d(TAG, "msg"); in .java code ]


input keyevent 82        unlocks screen of connected device






Saturday, April 14, 2012

SOLVED: R.layout.main cannot be resolved to a variable

This is a misleading error message. A telltale symptom is your class file contains
import android.R; in your imports list. Remove this line, then look for the real cause of the error message.

More than likely, there is an error in a /res file preventing the project's 'R' file from being generated. If Eclipse can't find one, it will use Android's 'R' file. Check your /res folder for errors (red icons indicate errors). Finding the root cause might not be easy, but once you find and fix the error (and save it), a new 'R' file will be automatically generated.

When that happens, all should again be well with your code.