In the process of updating and refactoring an old Android project I unwittingly changed a Project configuration option (the “Is Library” option) that lead to my resource file being generated differently. E.g
Before
public final class R {
public static final class id {
public static final int button1=0x7f090001;
public static final int button2=0x7f090002;
public static final int button3=0x7f090003;
}
}
After
public final class R {
public static final class id {
public static int button1=0x7f090001;
public static int button2=0x7f090002;
public static int button3=0x7f090003;
}
}
A subtle change indeed but one that caused the following compiler error for each line
case expressions must be constant expressions
Some googling lead me to a Stack Overflow page http://stackoverflow.com/questions/9092712/switch-case-statement-error-case-expressions-must-be-constant-expression wherein I found the root cause.
Most interestingly though, I came across the Quick Fix that would convert a switch statement into an if-else statement.
Tip
You can quickly convert aswitchstatement to anif-elsestatement using Eclipse’s quick fix.Click on the
switchkeyword and press Ctrl + 1 then selectConvert ‘switch’ to ‘if-else’.
What I would have given to have capability in some previous projects!
