【问题标题】:Google Maps Api android key谷歌地图 API 安卓密钥
【发布时间】:2011-02-20 02:06:03
【问题描述】:

我在测试包含谷歌地图 API 的 Android 应用程序时遇到了一些问题。 ooficial API 示例工作得很好,但如果我将代码复制到我自己的项目中,它会一直说:“应用程序已意外停止”。我在密钥库中查找了几次密钥,并在谷歌上注册了它。甚至尝试重新安装 SDK。有谁知道问题出在哪里?

提前致谢

05-16 14:31:11.142: 错误/ActivityThread(662): 找不到 com.google.settings 的提供者信息 05-16 14:31:11.150: 错误/ActivityThread(662): 找不到 com.google.settings 的提供者信息 05-16 14:31:12.598: 错误/MediaPlayerService(542): 无法为 content://settings/system/notification_sound 打开 fd 05-16 14:31:12.624: 错误/MediaPlayer(562): 无法创建媒体播放器 05-16 14:31:05.098: 错误/ActivityThread(608): 找不到 android.server.checkin 的提供者信息 05-16 14:31:06.538: 错误/ActivityThread(608): 找不到 android.server.checkin 的提供者信息 05-16 14:31:06.645: 错误/ActivityThread(608): 找不到 android.server.checkin 的提供者信息 05-16 14:31:12.803:错误/AndroidRuntime(715):错误:线程附加失败 05-16 14:31:13.698: 错误/ActivityThread(723): 找不到 com.google.settings 的提供者信息 05-16 14:31:13.987:错误/AndroidRuntime(723):未捕获的处理程序:线程主因未捕获的异常而退出

基本上我的代码是:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //connect to server

    //get current map scope

    //get media within map scope + a bit

    //init and show map
    setContentView(R.layout.main);
    //add zoom controls
    mapView = (MapView) findViewById(R.id.mapview);

    mapView.setBuiltInZoomControls(true); 


    //add menu
}

例外:

05-16 15:13:05.204: 错误/AndroidRuntime(726): java.lang.RuntimeException: 无法启动活动 ComponentInfo{org.diretto.client.smartphone.android/org.diretto.client.smartphone.android.AnDiretto} : android.view.InflateException: Binary XML file line #6: Error inflating class java.lang.reflect.Constructor 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.app.ActivityThread.access$1800(ActivityThread.java:112) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.os.Handler.dispatchMessage(Handler.java:99) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.os.Looper.loop(Looper.java:123) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.app.ActivityThread.main(ActivityThread.java:3948) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 java.lang.reflect.Method.invokeNative(Native Method) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 java.lang.reflect.Method.invoke(Method.java:521) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) 05-16 15:13:05.204:错误/AndroidRuntime(726):在 dalvik.system.NativeStart.main(本机方法) 05-16 15:13:05.204:错误/AndroidRuntime(726):原因:android.view.InflateException:二进制 XML 文件第 6 行:膨胀类 java.lang.reflect.Constructor 时出错 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.view.LayoutInflater.createView(LayoutInflater.java:512) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:564) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.view.LayoutInflater.rInflate(LayoutInflater.java:617) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.view.LayoutInflater.inflate(LayoutInflater.java:407) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.view.LayoutInflater.inflate(LayoutInflater.java:320) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.view.LayoutInflater.inflate(LayoutInflater.java:276) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.app.Activity.setContentView(Activity.java:1626) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 org.diretto.client.smartphone.android.AnDiretto.onCreate(AnDiretto.java:39) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231) 05-16 15:13:05.204: 错误/AndroidRuntime(726): ... 11 更多 05-16 15:13:05.204: 错误/AndroidRuntime(726): 由: java.lang.reflect.InvocationTargetException 引起 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 com.google.android.maps.MapView.(MapView.java:237) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 java.lang.reflect.Constructor.constructNative(Native Method) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 java.lang.reflect.Constructor.newInstance(Constructor.java:446) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 android.view.LayoutInflater.createView(LayoutInflater.java:499) 05-16 15:13:05.204: 错误/AndroidRuntime(726): ... 21 更多 05-16 15:13:05.204: ERROR/AndroidRuntime(726): Caused by: java.lang.IllegalStateException: 你只能在 MapActivity 中有一个 MapView 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 com.google.android.maps.MapActivity.setupMapView(MapActivity.java:180) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 com.google.android.maps.MapView.(MapView.java:279) 05-16 15:13:05.204: 错误/AndroidRuntime(726): 在 com.google.android.maps.MapView.(MapView.java:254) 05-16 15:13:05.204: 错误/AndroidRuntime(726): ... 25 更多

XML 文件第 6 行将是:

<com.google.android.maps.MapView android:id="@+id/mapview" ...

后面是其他几行 XML 参数

【问题讨论】:

  • 能否请您发布以下异常和一些代码?问题一定是其他问题,错误的 API 密钥不会导致强制关闭对话框,它只是显示一个空白网格而不是地图。

标签: android android-emulator google-maps


【解决方案1】:

首先,除非您确实提供了答案,否则不要回答您自己的问题。您可以编辑问题以添加新材料,例如更长的堆栈跟踪。

你的例外是:

Caused by: java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity

这是因为在MapActivity 中只允许有一个MapView,显然你有两个或更多。

【讨论】:

  • 不,main.xml 中只有一个 MapView,但这就是问题所在......如果我从 XML 文件中删除 mapview,程序就可以工作......
  • 您能否编辑您的问题并发布main.xml 文件?然后在这里评论,让它再次出现在我的队列中。
【解决方案2】:

我知道你已经解决了这个问题,但我遇到了同样的问题,这里是我关于同样问题的笔记以及我是如何解决它的。

You are only allowed to have a single MapView in a MapActivity

Delete a view and recreate it

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-15
    • 1970-01-01
    • 2016-09-30
    相关资源
    最近更新 更多