2010-05-16 148 views
0

我在测试包含google maps API的Android应用程序时遇到了一些麻烦。正式的API示例工作得很好,但如果我将代码复制到我自己的项目中,它会一直说:“应用程序意外停止”。我多次查看密钥库中的密钥并在谷歌上注册。甚至尝试重新安装SDK。有人知道问题是什么吗?Google Maps Api android key

在此先感谢

 
05-16 14:31:11.142: ERROR/ActivityThread(662): Failed to find provider info for com.google.settings 
05-16 14:31:11.150: ERROR/ActivityThread(662): Failed to find provider info for com.google.settings 
05-16 14:31:12.598: ERROR/MediaPlayerService(542): Couldn't open fd for content://settings/system/notification_sound 
05-16 14:31:12.624: ERROR/MediaPlayer(562): Unable to to create media player 
05-16 14:31:05.098: ERROR/ActivityThread(608): Failed to find provider info for android.server.checkin 
05-16 14:31:06.538: ERROR/ActivityThread(608): Failed to find provider info for android.server.checkin 
05-16 14:31:06.645: ERROR/ActivityThread(608): Failed to find provider info for android.server.checkin 
05-16 14:31:12.803: ERROR/AndroidRuntime(715): ERROR: thread attach failed 
05-16 14:31:13.698: ERROR/ActivityThread(723): Failed to find provider info for com.google.settings 
05-16 14:31:13.987: ERROR/AndroidRuntime(723): Uncaught handler: thread main exiting due to uncaught exception 

基本上我的代码是:

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: ERROR/AndroidRuntime(726): java.lang.RuntimeException: Unable to start activity  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: ERROR/AndroidRuntime(726):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.app.ActivityThread.access$1800(ActivityThread.java:112) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.os.Handler.dispatchMessage(Handler.java:99) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.os.Looper.loop(Looper.java:123) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.app.ActivityThread.main(ActivityThread.java:3948) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at java.lang.reflect.Method.invokeNative(Native Method) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at java.lang.reflect.Method.invoke(Method.java:521) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at dalvik.system.NativeStart.main(Native Method) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class java.lang.reflect.Constructor 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.view.LayoutInflater.createView(LayoutInflater.java:512) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:564) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:617) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.app.Activity.setContentView(Activity.java:1626) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at org.diretto.client.smartphone.android.AnDiretto.onCreate(AnDiretto.java:39) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  ... 11 more 
05-16 15:13:05.204: ERROR/AndroidRuntime(726): Caused by: java.lang.reflect.InvocationTargetException 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at com.google.android.maps.MapView.(MapView.java:237) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at java.lang.reflect.Constructor.constructNative(Native Method) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at android.view.LayoutInflater.createView(LayoutInflater.java:499) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  ... 21 more 
05-16 15:13:05.204: ERROR/AndroidRuntime(726): Caused by: java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:180) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at com.google.android.maps.MapView.(MapView.java:279) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  at com.google.android.maps.MapView.(MapView.java:254) 
05-16 15:13:05.204: ERROR/AndroidRuntime(726):  ... 25 more 

XML文件第6行是:

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

其后是其他的XML参数行

+0

能否请您发表以下异常和一些代码? 这个问题一定是别的,一个错误的API键不会导致强制关闭对话框,它只是显示一个空白的网格而不是地图。 – 2010-05-16 12:49:50

回答

2

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

您的例外是:

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

这是因为你只允许有一个MapViewMapActivity,显然你有两个或两个以上。

+0

不,在main.xml中只有一个MapView,但这是问题所在......如果我从XML文件中删除mapview程序工作... – Cookie 2010-05-16 14:40:55

+0

你可以编辑你的问题并发布'main。 xml'文件?然后在这里回复,以便它再次弹出我的队列。 – CommonsWare 2010-05-16 16:32:24