0

嗨,我苦苦挣扎了两天,在我的地图应用程序中,地图未显示并出现以下错误..我搜索了很多,但还没有得到任何合适的解决方案..

xml文件

    <RelativeLayout 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"
    tools:context=".MainActivity" >

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

MainActivity.java

    package com.example.googlegpstracker;

     import com.google.android.gms.common.GooglePlayServicesUtil;

     import android.os.Bundle;
      import android.support.v4.app.FragmentActivity;
    import android.view.Menu;

     public class MainActivity extends FragmentActivity {
    private GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}

mainfest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlegpstracker"
android:versionCode="1"

安卓:版本名称="1.0" >

 <uses-sdk
android:minSdkVersion="17"
 android:targetSdkVersion="17" />

     <permission
   android:name="com.example.googlegpstracker.permission.MAPS_RECEIVE"
     android:protectionLevel="signature" />



 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="com.example.googlegpstracker.permission.MAPS_RECEIVE" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
   android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
     android:theme="@style/AppTheme" >
     <activity
  android:name="com.example.googlegpstracker.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="AIzaSyC0hlJU8lEbvXmqckdUHHRhRoRkF0KpYR8" />
        </application>

   </manifest>

下面是我的 Logcat

     06-22 13:53:41.197: E/AndroidRuntime(1638): FATAL EXCEPTION: main
           06-22 13:53:41.197: E/AndroidRuntime(1638): java.lang.RuntimeException: Unable       to start activity        ComponentInfo{com.example.googlegpstracker/com.example.googlegpstracker.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
06-22 13:53:41.197: E/AndroidRuntime(1638):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-22 13:53:41.197: E/AndroidRuntime(1638):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-22 13:53:41.197: E/AndroidRuntime(1638):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-22 13:53:41.197: E/AndroidRuntime(1638):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-22 13:53:41.197: E/AndroidRuntime(1638):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-22 13:53:41.197: E/AndroidRuntime(1638):     at android.os.Looper.loop(Looper.java:137)
06-22 13:53:41.197: E/AndroidRuntime(1638):     at android.app.ActivityThread.main(ActivityThread.java:5041)
06-22 13:53:41.197: E/AndroidRuntime(1638):     at java.lang.reflect.Method.invokeNative(Native Method)
06-22 13:53:41.197: E/AndroidRuntime(1638):     at java.lang.reflect.Method.invoke(Method.java:511)
06-22 13:55:22.367: E/AndroidRuntime(1707): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: /data/app/com.example.googlegpstracker-1.apk
06-22 13:55:22.367: E/AndroidRuntime(1707):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
06-22 13:55:22.367: E/AndroidRuntime(1707):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-22 13:55:22.367: E/AndroidRuntime(1707):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-22 13:55:22.367: E/AndroidRuntime(1707):     at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
4

2 回答 2

0

似乎您没有将 Google Play Services SDK 引用为库项目,这可以解释为什么找不到该类。由于 com.google.android.gms.maps.SupportMapFragment 仅在 xml 中引用,因此它会在运行时出现,并且在运行应用程序之前您不会捕获它。

查看: https ://developers.google.com/maps/documentation/android/intro#sample_code

在这里了解有关设置 SDK 的信息:http: //developer.android.com/google/play-services/setup.html

于 2013-06-22T12:43:10.460 回答
0

试试这个。在此之前确保你有谷歌 API 并且你输入了正确的密钥和所有在你里面。

`

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />      
        <category android:name="android.intent.category.LAUNCHER" />    
    </intent-filter>

</activity>

<uses-library android:name="com.google.android.maps" />

`

于 2013-09-13T06:15:00.723 回答