映射没有加载并在android中显示错误

时间:2013-06-22 09:46:13

标签: android google-maps

您好我正在苦苦挣扎两天,在我的地图应用程序地图中没有显示并得到以下错误..我搜索了很多并且没有得到任何适当的解决方案..

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"

android:versionName =“1.0”&gt;

 <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)

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

请尝试此操作。在此之前,请确保您使用的是Google 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" />

`