Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 谷歌地图活动在成功安装后崩溃_Android_Google Maps_Google Maps Api 3 - Fatal编程技术网

Android 谷歌地图活动在成功安装后崩溃

Android 谷歌地图活动在成功安装后崩溃,android,google-maps,google-maps-api-3,Android,Google Maps,Google Maps Api 3,不知道为什么会发生这种情况,应用程序没有显示错误,我也成功地获得了密钥,但活动没有运行 这是我的MapScreen类: package com.example.prateekchachra.projectconnecttoastmasters; import android.app.Activity; import android.content.pm.PackageManager; import android.os.Persi

不知道为什么会发生这种情况,应用程序没有显示错误,我也成功地获得了密钥,但活动没有运行

这是我的MapScreen类:

            package com.example.prateekchachra.projectconnecttoastmasters;        

    import android.app.Activity;
    import android.content.pm.PackageManager;
    import android.os.PersistableBundle;
    import android.support.annotation.Nullable;
    import android.support.v4.app.ActivityCompat;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentActivity;
    import android.os.Bundle;
    import android.support.v4.app.FragmentManager;
    import android.support.v7.app.AppCompatActivity;        

    import com.google.android.gms.maps.CameraUpdateFactory;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.MapFragment;
    import com.google.android.gms.maps.OnMapReadyCallback;
    import com.google.android.gms.maps.SupportMapFragment;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.Marker;
    import com.google.android.gms.maps.model.MarkerOptions;        

    /**
     * Created by Prateek Chachra on 5/23/2016.
     */
    public class MapScreen extends Activity{
        static final LatLng Pos = new LatLng(40, -79);
        private GoogleMap googleMap;        


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_maps);
            try {
                if (googleMap == null) {        

                    googleMap = ((MapFragment) getFragmentManager()
                            .findFragmentById(R.id.map)).getMap();
                }
                googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    // TODO: Consider calling
                    //    ActivityCompat#requestPermissions
                    // here to request the missing permissions, and then overriding
                    //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                    //                                          int[] grantResults)
                    // to handle the case where the user grants the permission. See the documentation
                    // for ActivityCompat#requestPermissions for more details.
                    return;
                }
                googleMap.setMyLocationEnabled(true);
                googleMap.setTrafficEnabled(true);
                googleMap.getUiSettings().setZoomControlsEnabled(true);        

                Marker marker = googleMap.addMarker(new MarkerOptions().position(Pos).title("That is my loc"));        

        } catch(Exception e){
        e.printStackTrace();
    }
        }        



    }        
以下是我的activity_maps.xml文件:

            <?xml version = "1.0" encoding = "utf-8" ?>
    <RelativeLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android" >
    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.prateekchachra.projectconnecttoastmasters.MapsActivity" />
    </RelativeLayout>

Android清单:

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

        <!--
             The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
             Google Maps Android API v2, but you must specify either coarse or fine
             location permissions for the 'MyLocation' functionality. 
        -->
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <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="com.google.android.providers.gsf.permission.READ_GSERVICES" />
        <permission android:name="com.example.prateekchachra.projectconnecttoastmasters.permission.MAPS_RECEIVE"
            android:protectionLevel="signature"/>
        <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true" />
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">        

            <!--
                 The API key for Google Maps-based APIs is defined as a string resource.
                 (See the file "res/values/google_maps_api.xml").
                 Note that the API key is linked to the encryption key used to sign the APK.
                 You need a different API key for each encryption key, including the release key that is used to
                 sign the APK for publishing.
                 You can define the keys for the debug and release targets in src/debug/ and src/release/. 
            -->
            <meta-data
                android:name="com.google.android.geo.API_KEY"
                android:value="ID" />        

            <activity
                android:name=".MapsActivity"
                android:label="@string/title_activity_maps">        

            </activity>
            <activity android:name=".Events"
                android:label="Events List">
            </activity>
            <activity android:name=".FindSlots"
                android:label="Find Slots">
            </activity>
            <activity android:name=".MapScreen"
                android:label="Map Main">
    </activity>
            <activity android:name=".SplashScreen"
                android:label="Splash Screen">        

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

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


        </application>        

    </manifest>

Logcat输出:

05-24 03:59:40.867 26851-26851/com.example.prateekchachra.projectconnecttoastmasters E/AndroidRuntime:致命异常:main java.lang.RuntimeException:无法启动活动组件信息{com.example.prateekchachra.projectconnecttoastmasters/com.example.prateekchachra.projectconnecttoastmasters.MapScreen}:android.view.InflateException:二进制XML文件行#5:膨胀类片段时出错 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343) 位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395) 在android.app.ActivityThread.access$600(ActivityThread.java:162) 在android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 位于android.os.Handler.dispatchMessage(Handler.java:107) 位于android.os.Looper.loop(Looper.java:194) 位于android.app.ActivityThread.main(ActivityThread.java:5371) 位于java.lang.reflect.Method.Invokenactive(本机方法) 位于java.lang.reflect.Method.invoke(Method.java:525) 在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run上(ZygoteInit.java:833) 位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 在dalvik.system.NativeStart.main(本机方法) 原因:android.view.InflateException:二进制XML文件行#5:膨胀类片段时出错 位于android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 位于android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 在android.view.LayoutInflater.充气(LayoutInflater.java:489) 在android.view.LayoutInflater.inflate(LayoutInflater.java:396) 在android.view.LayoutInflater.充气(LayoutInflater.java:352) 位于com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281) 位于android.app.Activity.setContentView(Activity.java:1881) 位于com.example.prateekchachra.projectconnecttoastmasters.MapScreen.onCreate(MapScreen.java:34) 位于android.app.Activity.performCreate(Activity.java:5122) 位于android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307) 位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395) 在android.app.ActivityThread.access$600(ActivityThread.java:162) 在android.app.ActivityThread$H.H
    android:name="com.google.android.gms.maps.SupportMapFragment" 
Replace with your Fragment package and fragment name like 
android:name="com.example.prateekchachra.projectconnecttoastmasters.MapScreen"