读取设备中的Android错误中的谷歌地图集成(三星Galaxy S3)

时间:2014-11-22 07:47:02

标签: android google-maps map google-maps-android-api-2 google-maps-api-2

我是Android和Google Map Integration的初学者。我在Google地图中遇到问题。我在谷歌以及这个网站上搜索过但我找不到合适的解决方案。我尝试了大部分解决方案,但仍然无法解决我的问题。如果任何人有解决方案,那么请帮我解决问题。 我发布了包含ERROR消息的整个代码

activity_main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.googlemapexaple.MainActivity" >

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

</LinearLayout>

MainActivity.java

package com.example.googlemapexaple;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class MainActivity extends FragmentActivity {

    private SupportMapFragment map;
    private GoogleMap googleMap;

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

        int service = GooglePlayServicesUtil
                .isGooglePlayServicesAvailable(this);
        if (service == ConnectionResult.SERVICE_MISSING) {
            Toast.makeText(this, "Google Play Service is Missing!!",
                    Toast.LENGTH_LONG).show();
        }
        if (service == ConnectionResult.SERVICE_INVALID) {
            Toast.makeText(this, "Google Play Service is Invalid!!",
                    Toast.LENGTH_LONG).show();
        }
        if (service == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED) {
            Toast.makeText(this, "Google Play Service is Updated!!",
                    Toast.LENGTH_LONG).show();
        }
        if (service == ConnectionResult.SUCCESS) {

            map = (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map);
            googleMap = map.getMap();
            googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        }
    }

}

的AndroidManifest.xml

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

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

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

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

    <!--
     The following two permissions are not required to use
     Google Maps Android API v2, but are recommended.
    -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

    <!-- Required OpenGL ES 2.0. for Maps V2 -->

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library
            android:name="com.google.android.maps"
            android:required="true" />

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyD4ON_sFdsr5udAZZAbL2YWlAdqixn_Q_0" />

        <activity
            android:name="com.example.googlemapexaple.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>


    </application>

</manifest> 

proguard的-project.txt

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

现在我在这里发布logcat

中显示错误
11-22 13:13:38.995: I/dalvikvm(17645): Could not find method com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable, referenced from method com.example.googlemapexaple.MainActivity.onCreate
11-22 13:13:38.995: W/dalvikvm(17645): VFY: unable to resolve static method 9318: Lcom/google/android/gms/common/GooglePlayServicesUtil;.isGooglePlayServicesAvailable (Landroid/content/Context;)I
11-22 13:13:38.995: D/dalvikvm(17645): VFY: replacing opcode 0x71 at 0x000a
11-22 13:13:39.390: D/AndroidRuntime(17645): Shutting down VM
11-22 13:13:39.390: W/dalvikvm(17645): threadid=1: thread exiting with uncaught exception (group=0x41d12700)
11-22 13:13:39.420: E/AndroidRuntime(17645): FATAL EXCEPTION: main
11-22 13:13:39.420: E/AndroidRuntime(17645): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemapexaple/com.example.googlemapexaple.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.os.Looper.loop(Looper.java:176)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.app.ActivityThread.main(ActivityThread.java:5419)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at java.lang.reflect.Method.invokeNative(Native Method)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at java.lang.reflect.Method.invoke(Method.java:525)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at dalvik.system.NativeStart.main(Native Method)
11-22 13:13:39.420: E/AndroidRuntime(17645): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:361)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.app.Activity.setContentView(Activity.java:1956)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at com.example.googlemapexaple.MainActivity.onCreate(MainActivity.java:20)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.app.Activity.performCreate(Activity.java:5372)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
11-22 13:13:39.420: E/AndroidRuntime(17645):    ... 11 more
11-22 13:13:39.420: E/AndroidRuntime(17645): 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-22 13:13:39.420: E/AndroidRuntime(17645):    at android.app.Fragment.instantiate(Fragment.java:596)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.app.Fragment.instantiate(Fragment.java:560)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.app.Activity.onCreateView(Activity.java:4958)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
11-22 13:13:39.420: E/AndroidRuntime(17645):    ... 21 more
11-22 13:13:39.420: E/AndroidRuntime(17645): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: /system/framework/com.google.android.maps.jar:/data/app/com.example.googlemapexaple-1.apk
11-22 13:13:39.420: E/AndroidRuntime(17645):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-22 13:13:39.420: E/AndroidRuntime(17645):    at android.app.Fragment.instantiate(Fragment.java:582)
11-22 13:13:39.420: E/AndroidRuntime(17645):    ... 24 more

请给我解决问题的方法。以及我正在尝试MapFragment with Activity但仍然显示此错误。只是在找不到MapFragment的情况下更改类。

1 个答案:

答案 0 :(得分:0)

在API版本11之后支持片段功能。我已经看到你写了min sdk版本8将其更改为11或大于11.不要将它保持在11以下。 像这样

我希望它能奏效。

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