android谷歌地图API问题

时间:2014-11-28 11:18:34

标签: java android google-maps google-maps-api-3

是的,我知道这个问题已经在很多地方得到了回答,但我没有遇到什么问题,我最近搬到了Android应用程序并试图在我的应用程序上使用地图。

我完全按照这些链接:

https://www.youtube.com/watch?v=wNlleczyPjs

https://developers.google.com/maps/documentation/android/start#install_and_configure_the_google_play_services_sdk

所以我的问题是,我还能做些什么呢。我只是不明白......

我的感觉是我的密钥没有正确注册,但是当我创建新密钥时,我提供了以下信息:

Android apps:   
9D:7C:<THIS BIT IS SECRET>84:0F;com.example.myapp

额外信息

这是错误日志:

11-28 11:09:59.471: E/AndroidRuntime(31683): FATAL EXCEPTION: main
11-28 11:09:59.471: E/AndroidRuntime(31683): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.os.Looper.loop(Looper.java:137)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.app.ActivityThread.main(ActivityThread.java:4898)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at java.lang.reflect.Method.invokeNative(Native Method)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at java.lang.reflect.Method.invoke(Method.java:511)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at dalvik.system.NativeStart.main(Native Method)
11-28 11:09:59.471: E/AndroidRuntime(31683): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.app.Activity.setContentView(Activity.java:1924)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at com.example.myapp.MainActivity.onCreate(MainActivity.java:8)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.app.Activity.performCreate(Activity.java:5206)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
11-28 11:09:59.471: E/AndroidRuntime(31683):    ... 11 more
11-28 11:09:59.471: E/AndroidRuntime(31683): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.app.Fragment.instantiate(Fragment.java:584)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.app.Fragment.instantiate(Fragment.java:552)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.app.Activity.onCreateView(Activity.java:4849)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
11-28 11:09:59.471: E/AndroidRuntime(31683):    ... 20 more
11-28 11:09:59.471: E/AndroidRuntime(31683): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
11-28 11:09:59.471: E/AndroidRuntime(31683):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-28 11:09:59.471: E/AndroidRuntime(31683):    at android.app.Fragment.instantiate(Fragment.java:574)
11-28 11:09:59.471: E/AndroidRuntime(31683):    ... 23 more
11-28 11:09:59.511: D/dalvikvm(31683): GC_CONCURRENT freed 190K, 9% free 12391K/13575K, paused 12ms+2ms, total 36ms

这是代码:

package com.example.myapp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

这是androidManifext.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk  android:minSdkVersion="8"   android:targetSdkVersion="21" /> 
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
                <meta-data android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzXXXXXXXXXXXXXXXXXXXXXwKo"/>
                <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>
</manifest>

这是main_activity.xml布局:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  class="com.google.android.gms.maps.SupportMapFragment"/>

提前致谢。

IT工作 耶稣,它刚开始没有在哪里工作。日食刚刚上市,我花了大约10分钟让日食工作。现在它刚开始工作,应用程序也是如此。我不知道发生了什么,也不知道为什么它会让我烦恼。基本上我只能说api键上班需要几个小时。

3 个答案:

答案 0 :(得分:0)

我不确定这是否是造成问题的原因但是我觉得你的main_activity.xml没有布局容器,例如LinearLayout,RelativeLayout ..

您可以尝试使main_activity.xml看起来像这样,看看会发生什么:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    <fragment 
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"/>
</LinearLayout>

或者我建议尝试使用vogella http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html的教程,它对我来说非常有用。

再次阅读错误日志,我想知道您是否已将支持库添加到项目中。在eclipse中它就像:Rightclick项目 - &gt; Android工具 - &gt;添加支持库...

答案 1 :(得分:0)

plz添加此权限然后才能使用

<permission
        android:name="<your package name>.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="<your package name>.permission.MAPS_RECEIVE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

答案 2 :(得分:0)

我正在使用......

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<fragment
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    class="com.google.android.gms.maps.MapFragment" />

它适用于我