0

I have this code:

for (RoomProperties RP : roomHashMap.values()) {
    canvas.drawRect(RP.left, RP.top, RP.right, RP.bottom, snowWhite);
}

it's properly compiled. But the rectangle simply will not be drawn, so I entered debug mode and sure enough there are these errors:

RP.left Cannot find local variable 'RP' RP.right Cannot find local variable 'RP'

Now, this is practically confusing. Suppose I didn't get the for each right, but why was it compiled and run???

What's the proper way to do foreach and what's wrong with the compiler not reporting error (I probably ignored warnings)?

Vampire
  • 35,631
  • 4
  • 76
  • 102
VictorCharlie23
  • 121
  • 1
  • 10
  • How does it relate to gradle? – Opal Oct 12 '17 at 10:10
  • I'm sorry I thought gradle is a comprehensive compiler used in android studio... – VictorCharlie23 Oct 12 '17 at 11:00
  • Like Per Huss wrote, that is the Debugger not finding Information about the Variable Name. A (recent) standard Android Studio Project, like from Version 2.0+, should automatically [build the debug Variant](https://developer.android.com/studio/run/index.html#changing-variant) as long as you do not explicitly build the release or modify the configs. Some problems may arise with certain Gradle configs.. but it's hard to tell without more information. This [Question about Debugging with Android Studio](https://stackoverflow.com/q/37142275/3828957) may as well be interesting. – makadev Oct 12 '17 at 14:14

1 Answers1

1

I suspect the cannot find local variable message you see is the debugger informing you that it is unable to resolve the local variable for you. In that case it is not a runtime problem at all, and is easily fixed by making sure you compile your java code with "generate debugging info" or similar option enabled. This will add extra info to the compiled code to help the debugger. Good luck with your debugging!

Per Huss
  • 4,755
  • 12
  • 29