When compiling for the debugger the Basic4android compiler inserts code that identifies the line being executed and which local variables a Sub uses. In this case because of the "Dim" it is assuming that a global variable is in fact a local one and that is causing the error.