Possible Duplicate:
#ifdef #ifndef in Java
I’m trying to implement some debug messages in my Android code by using something like this:
private static final boolean DEBUG = false;
if (DEBUG) {
// some code
}
However, upon compilation I keep getting “Illegal start of expression” errors. final boolean works, but neither static nor private work.
I’m declaring the DEBUG variable in methods. Would also appreciate if there’s a way to make this global so that everything within the same Java file will see it rather than me having to declare it in every method that needs it.
Thanks!
You have to declare the variable at the class-level, if you want the variable to be visible to all the methods in that class.
If your doing the following inside a method:
the problem is that the modifiers
privateandstaticare not allowed within a method.Actually, you should be using logger for this kind of purpose.