简体   繁体   English

Google Maps API v2的片段错误瞬间膨胀

[英]Fragment error whem inflating for Google Maps API v2

I am trying to make a more complicated app involving the Google Maps API, however I started out simple and tried to show a map on my second activity. 我试图制作一个涉及Google Maps API的更复杂的应用程序,但是我起初很简单,尝试在第二个活动中显示地图。 I've seen a few tutorials and did what they said but I keep on seeing this exception: 我看过一些教程,做了他们说的话,但是我继续看到这个异常:

03-16 16:17:25.645: E/AndroidRuntime(6665): FATAL EXCEPTION: main
03-16 16:17:25.645: E/AndroidRuntime(6665): Process: com.geoloctarna, PID: 6665
03-16 16:17:25.645: E/AndroidRuntime(6665): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.geoloctarna/com.geoloctarna.Mapa}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.app.ActivityThread.access$900(ActivityThread.java:161)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.os.Handler.dispatchMessage(Handler.java:102)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.os.Looper.loop(Looper.java:157)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.app.ActivityThread.main(ActivityThread.java:5356)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at java.lang.reflect.Method.invokeNative(Native Method)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at java.lang.reflect.Method.invoke(Method.java:515)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at dalvik.system.NativeStart.main(Native Method)
03-16 16:17:25.645: E/AndroidRuntime(6665): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.app.Activity.setContentView(Activity.java:2010)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at com.geoloctarna.Mapa.onCreate(Mapa.java:9)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.app.Activity.performCreate(Activity.java:5426)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
03-16 16:17:25.645: E/AndroidRuntime(6665):     ... 11 more
03-16 16:17:25.645: E/AndroidRuntime(6665): Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class com.google.android.gms.maps.SupportMapFragment that is not a Fragment
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.app.Fragment.instantiate(Fragment.java:585)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.app.Fragment.instantiate(Fragment.java:561)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.app.Activity.onCreateView(Activity.java:4964)
03-16 16:17:25.645: E/AndroidRuntime(6665):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
03-16 16:17:25.645: E/AndroidRuntime(6665):     ... 21 more
03-16 16:17:25.645: E/AndroidRuntime(6665): Caused by: java.lang.ClassCastException
03-16 16:17:25.645: E/AndroidRuntime(6665):     ... 25 more

Here's my manifest: 这是我的清单:

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

    <permission
                android:name="org.example.androidmaps.permission.MAPS_RECEIVE"
                android:protectionLevel="signature"/>

            <uses-permission
                android:name="org.example.ejemplogooglemaps.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"/>
            <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
            <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


            <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />



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

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

        <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>
        <activity android:name="com.geoloctarna.Mapa"/>

        <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="AIzaSyCuDKWMbbwGbwJ1yhpOQFtrBPEv4iYjlDE"/>

    </application>

</manifest>

Activity code: 活动代码:

package com.geoloctarna;

import android.app.Activity;
import android.os.Bundle;
public class Mapa extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapa);
    }
}

and XML layout: 和XML布局:

<?xml version="1.0" encoding="utf-8"?>
<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"
        android:name="com.geoloctarna.MainActivity"
        class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>

The Errors keep talking about an "XML binary file", but I don't know which file is that. 错误一直在谈论“ XML二进制文件”,但我不知道那是哪个文件。 I've seen many other questions like this but no answer has helped me, so Thanks in advnace. 我已经看到许多其他类似问题,但没有答案对我有帮助,因此感谢您。

from: 从:

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

layout should be: 布局应为:

 <?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"
      android:name="com.google.android.gms.maps.MapFragment"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM