Error when debugging foreach with Hashmap

时间:2017-10-12 09:57:06

标签: java android debugging

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)?

1 个答案:

答案 0 :(得分:1)

我怀疑无法找到本地变量消息,您看到的是调试器,通知您无法为您解析本地变量。在这种情况下,它根本不是运行时问题,并且可以通过确保使用“生成调试信息”或启用类似选项来编译Java代码来轻松修复。这将为编译的代码添加额外的信息以帮助调试器。祝你好好调试!