谷歌地图Android V2 - 调试时的空白屏幕(Google Maps Android V2 - Blank Screen When Debug)
我有一个奇怪的问题。
我尝试使用Android SDK中的标准Google Maps V2示例。 但我将其导入Android Studio。
我为此示例应用制作了Google API密钥,然后我签署了该应用。
奇怪的是,当我尝试从Android Studio调试我的设备上的应用程序时 - 然后我得到一个空白屏幕而不是地图。 但是当我制作一个签名的apk然后手动将它安装在我的设备上时 - 没关系,我可以看到地图。
调试模式有什么问题?
I have a strange problem.
I try to use standard Google Maps V2 sample from an Android SDK. But I import it to Android Studio.
I made Google API key for this sample app and I signed the app.
Strange is that when I try to debug the app on my device from Android Studio - then I get a Blank Screen instead the map. But when I make a signed apk and then install it on my device manually - it's all right, I can see the map.
What's wrong with the debug mode?
原文:
最满意答案
tl; dr:您似乎在Groovy的运行时参数重载评估中发现了一个错误。
回答:
map[gString]
在运行时通过Groovy的运算符重载机制直接计算为map.getAt(gString)
。 到目前为止,这么好,但现在一切都开始出错了。 JavaLinkedHashMap
类在其类型层次结构中的任何位置都没有getAt
方法,因此Groovy必须使用动态关联的mixin方法(实际上该语句有点颠倒。在类层次结构中使用声明的方法之前, Groovy使用mixin方法。)因此,长话短说,Groovy解析
map.getAt(gString)
以使用类别方法DefaultGroovyMethods.getAt()
。 轻松,对吧? 除了这个方法有大量不同的参数重载,其中有几个可能适用,特别是考虑到Groovy的默认参数强制。不幸的是,Groovy选择
DefaultGroovyMethods.getAt(Object,String)
而不是选择DefaultGroovyMethods.getAt(Map<K,V>,K)
,这似乎是一个完美的匹配,它将GString
键参数强制转换为String
。 由于实际的键实际上是GString
,因此该方法最终无法找到该值。对我来说真正的杀手是,如果参数重载决策是直接从代码执行的(而不是在运算符解析和类别方法选择之后),那么Groovy会做出正确的重载选择! 也就是说,如果替换此表达式:
map[gString]
用这个表达式:
DefaultGroovyMethods.getAt(map,gString)
然后正确解析参数重载,找到并返回正确的值。
tl;dr: You seem to have discovered a bug in Groovy's runtime argument overloading evaluation.
Answer:
map[gString]
is evaluated asmap.getAt(gString)
at runtime straightforwardly via Groovy's operator overloading mechanism. So far, so good, but now is where everything starts to go awry. The JavaLinkedHashMap
class does not have agetAt
method anywhere in it's type hierarchy, so Groovy must use dynamically associated mixin methods instead (Actually that statement is sort of reversed. Groovy uses mixin methods before using the declared methods in the class hierarchy.)So, to make a long story short, Groovy resolves
map.getAt(gString)
to use the category methodDefaultGroovyMethods.getAt()
. Easy-peasy, right? Except that this method has a large number of different argument overloads, several of which might apply, especially when you take Groovy's default argument coercion into account.Unfortunately, instead of choosing
DefaultGroovyMethods.getAt(Map<K,V>,K)
, which would seem to be a perfect match, Groovy choosesDefaultGroovyMethods.getAt(Object,String)
, which coerces theGString
key argument into aString
. Since the actual key is in fact aGString
, the method ultimately fails to find the value.To me the real killer is that if the argument overload resolution is performed directly from code (instead of after the operator resolution and the category method selection), then Groovy makes the right overload choice! That is to say, if you replace this expression:
map[gString]
with this expression:
DefaultGroovyMethods.getAt(map,gString)
then the argument overloading is resolved correctly, and the correct value is found and returned.
相关问答
更多-
通过Groovy中的地图循环?(Loop through Map in Groovy?)[2022-03-17]
相当简单的关闭: def map = [ 'iPhone':'iWebOS', 'Android':'2.3.3', 'Nokia':'Symbian', 'Windows':'WM8' ] map.each{ k, v -> println "${k}:${v}" } Quite simple with a closure: def map = [ 'iPhone':'i ... -
是的,只是做: def checkouts = repos.collect{ "$it = ${it}_checkout" } 或者,根据您声明属性的方式,您可以执行以下操作: root_checkout = 'woo' repo_checkout = 'yay' ['root', 'repo'].collect { r -> "$r = ${getProperty(r + '_checkout')}" } Yeh, just do: def checkouts = repos.collect{ "$ ...
-
由于GString是在编译时由groovy编译器构造的,因此XML文件不会返回GString。 解析XML文件时,您将获得String,而不是已编译的Groovy可执行文件。 如果你真的想在XML文档中嵌入groovy代码(这是你真正想要做的),那么你应该首先看一下: 嵌入Groovy 。 基本上,您将在SQL中读取并将其视为嵌入式groovy脚本。 另一种方法(我遇到类似问题时采用的方法)是使用MessageFormat替换XML中的值。 def s = '
Some SQ ... -
有两种逃避$ foo的方法: 将'$'作为'\''转义 使用'而不是'作为字符串分隔符 例: def test = "bad" def s0 = "$test" def s1 = "\$test" assert s1 != s0 def s2 = '$test' assert s2 == s1 println s0 println s1 println s2 所以我猜你必须使用你的预处理器来逃避你的字符串 there are two way to escape the $foo: esc ...
-
如何在gstring数据库查询中执行groovy中的函数(How to execute functions in gstring database queries for groovy)[2022-04-21]
你可以通过这种方式将它们嵌入到字符串中来完成它: sql.call("{call myfunction(${(int) (Calendar.instance.timeInMillis/1000)}, ..., ${input.isManager ? 1 : 0}, ...}") 那么由于SQL应该忽略换行符(如果不在中间的话)(我绝对不记得这个),你可以使用三重双转义字符串(一个强大的名字): """call myfunction${(int) (Ca ... -
GSP解析器不喜欢${...}块中的${...} 。 试试这个: <%= Foo.findAllByBar(bar).collect { it.name } %> The GSP parser doesn't like } within the ${...} block. Try this one: <%= Foo.findAllByBar(bar).collect { it.name } %>
-
tl; dr:您似乎在Groovy的运行时参数重载评估中发现了一个错误。 回答: map[gString]在运行时通过Groovy的运算符重载机制直接计算为map.getAt(gString) 。 到目前为止,这么好,但现在一切都开始出错了。 Java LinkedHashMap类在其类型层次结构中的任何位置都没有getAt方法,因此Groovy必须使用动态关联的mixin方法(实际上该语句有点颠倒。在类层次结构中使用声明的方法之前, Groovy使用mixin方法。) 因此,长话短说,Groovy解析ma ...
-
为什么我无法获得与Groovy中映射完全相同的GString?(Why I cannot get exactly the same GString as was put to map in Groovy?)[2023-04-21]
tl; dr:您似乎在Groovy的运行时参数重载评估中发现了一个错误。 回答: map[gString]在运行时通过Groovy的运算符重载机制直接计算为map.getAt(gString) 。 到目前为止,这么好,但现在一切都开始出错了。 Java LinkedHashMap类在其类型层次结构中的任何位置都没有getAt方法,因此Groovy必须使用动态关联的mixin方法(实际上该语句有点颠倒。在类层次结构中使用声明的方法之前, Groovy使用mixin方法。) 因此,长话短说,Groovy解析ma ... -
Groovy的“in”运算符,用于包含String和GString元素的列表(Groovy's “in” operator for lists with String and GString elements)[2022-03-31]
你可以使用*. 扩展运算符以轻松获取字符串(请参阅下面的list2示例)。 但是你的检查可以通过intersect更容易完成。 Listlist = ["test-${1+2}", "test-${2+3}", "test-${3+4}"] List subl = ["test-1", "test-2", "test-3"] assert subl.findAll{ it in list }==[] // wrong // use intersect for a shor ... -
下标符号是否对String有隐式转换? 基本上,是的。 声明a[b] = c等同于根据Groovy 运算符重载规则调用a.putAt(b, c)方法。 putAt方法的特定签名是void putAt(String property, Object newValue) ,这意味着如果b是Groovy String,它将首先使用其toString()方法转换为String。 最终, putAt方法将使用String值作为键调用Map.put 。 Does the subscript notation have ...