Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.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
google map无法启动activity ComponentInfo android.view.InflateException:二进制XML文件行#6:膨胀类片段时出错_Android_Google Play Services - Fatal编程技术网

google map无法启动activity ComponentInfo android.view.InflateException:二进制XML文件行#6:膨胀类片段时出错

google map无法启动activity ComponentInfo android.view.InflateException:二进制XML文件行#6:膨胀类片段时出错,android,google-play-services,Android,Google Play Services,我正试图用谷歌地图构建一个应用程序,当我试图运行时,我发现了一个错误 但我有以下错误 05-20 17:38:42.448: W/dalvikvm(722): threadid=1: thread exiting with uncaught exception (group=0x40a13300) 05-20 17:38:42.458: E/AndroidRuntime(722): FATAL EXCEPTION: main 05-20 17:38:42.458: E/AndroidRuntim

我正试图用谷歌地图构建一个应用程序,当我试图运行时,我发现了一个错误

但我有以下错误

05-20 17:38:42.448: W/dalvikvm(722): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
05-20 17:38:42.458: E/AndroidRuntime(722): FATAL EXCEPTION: main
05-20 17:38:42.458: E/AndroidRuntime(722): java.lang.RuntimeException: Unable to resume activity {info.androidhive.googlemapsv2/info.androidhive.googlemapsv2.MainActivity}: java.lang.NullPointerException
05-20 17:38:42.458: E/AndroidRuntime(722):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2575)
05-20 17:38:42.458: E/AndroidRuntime(722):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)
05-20 17:38:42.458: E/AndroidRuntime(722):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2089)
05-20 17:38:42.458: E/AndroidRuntime(722):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
05-20 17:38:42.458: E/AndroidRuntime(722):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
05-20 17:38:42.458: E/AndroidRuntime(722):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 17:38:42.458: E/AndroidRuntime(722):  at android.os.Looper.loop(Looper.java:137)
05-20 17:38:42.458: E/AndroidRuntime(722):  at android.app.ActivityThread.main(ActivityThread.java:4745)
05-20 17:38:42.458: E/AndroidRuntime(722):  at java.lang.reflect.Method.invokeNative(Native Method)
05-20 17:38:42.458: E/AndroidRuntime(722):  at java.lang.reflect.Method.invoke(Method.java:511)
05-20 17:38:42.458: E/AndroidRuntime(722):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-20 17:38:42.458: E/AndroidRuntime(722):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-20 17:38:42.458: E/AndroidRuntime(722):  at dalvik.system.NativeStart.main(Native Method)
05-20 17:38:42.458: E/AndroidRuntime(722): Caused by: java.lang.NullPointerException
05-20 17:38:42.458: E/AndroidRuntime(722):  at info.androidhive.googlemapsv2.MainActivity.initilizeMap(MainActivity.java:135)
05-20 17:38:42.458: E/AndroidRuntime(722):  at info.androidhive.googlemapsv2.MainActivity.onResume(MainActivity.java:126)
05-20 17:38:42.458: E/AndroidRuntime(722):  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)
05-20 17:38:42.458: E/AndroidRuntime(722):  at android.app.Activity.performResume(Activity.java:5082)
05-20 17:38:42.458: E/AndroidRuntime(722):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)
05-20 17:38:42.458: E/AndroidRuntime(722):  ... 12 more
活动主XML

<?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"
          class="com.google.android.gms.maps.SupportMapFragment"/>

请任何人帮我解决这个问题

Minifest xml

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

    <permission
        android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />

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

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

    <!-- Required to show current location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_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">
        <activity
            android:name="info.androidhive.googlemapsv2.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppBaseTheme">
            <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.gms.version"
android:value="@integer/google_play_services_version" />
        <!-- Goolge API Key -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyBZMlkOv4sj-M5JO9p6wksdax4TEjDVLgo" />
        </application>

</manifest>

Globals 立即创建 在oncreate之外,创建一个新方法\u SetMap Xml

在应用程序标记定义之外的清单文件中

和清单定义的应用程序标记中

现在
您必须从sdk/extra/google导入工作区中的google play服务

package info.androidhive.googlemapsv2;

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

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.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends FragmentActivity  {

    // Google Map
    private GoogleMap googleMap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

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

    }

    @Override
    protected void onResume() {
        super.onResume();
        initilizeMap();
    }

    /**
     * function to load map If map is not created it will create it for you
     * */

    private void _SetMap() {
        if (googleMap == null)
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMap();
        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    }


    private void initilizeMap() {
        if (googleMap == null) {
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMap();

            // check if map is created successfully or not
            if (googleMap == null) {
                Toast.makeText(getApplicationContext(),
                        "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }

    /*
     * creating random postion around a location for testing purpose only
     */
    private double[] createRandLocation(double latitude, double longitude) {

        return new double[] { latitude + ((Math.random() - 0.5) / 500),
                longitude + ((Math.random() - 0.5) / 500),
                150 + ((Math.random() - 0.5) * 10) };
    }
}

请花费你的布局文件和清单。同时发布日志。发布你的MainActivity.java。还有第135行是什么???发布你的代码。不要以图片的形式发布。请发布有问题的日志…不能以代码的形式发布。。它显示的代码太多了,你能帮我添加
private void initilizeMap()以上
私有谷歌地图谷歌地图。告诉我发生了什么。。是的,我做了你说的所有更改,但只有当我尝试运行google play console上google Map api v2的按钮时,我仍然会遇到相同的错误?否,我无法运行该应用程序。收到警报“不幸的是google map v2已停止”,请检查我的更新代码dude..并将清单文件与我的数据匹配..然后打开开发人员控制台上的google map API v2按钮。
private GoogleMap googleMap;
 try{
      _SetMap();
 }catch(Exception e){
    e.printStackTrace();
 }
private void _SetMap() {
    if (googleMap == null)
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();
    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

 <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/> 


</LinearLayout>
<permission
    android:name="YourPackageName.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
    <uses-permission android:name="YourPackageName.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
   <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
   <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
  <!-- Google API Key -->
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="YOURAPIKEY" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
package info.androidhive.googlemapsv2;

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

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.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends FragmentActivity  {

    // Google Map
    private GoogleMap googleMap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

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

    }

    @Override
    protected void onResume() {
        super.onResume();
        initilizeMap();
    }

    /**
     * function to load map If map is not created it will create it for you
     * */

    private void _SetMap() {
        if (googleMap == null)
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMap();
        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    }


    private void initilizeMap() {
        if (googleMap == null) {
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMap();

            // check if map is created successfully or not
            if (googleMap == null) {
                Toast.makeText(getApplicationContext(),
                        "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }

    /*
     * creating random postion around a location for testing purpose only
     */
    private double[] createRandLocation(double latitude, double longitude) {

        return new double[] { latitude + ((Math.random() - 0.5) / 500),
                longitude + ((Math.random() - 0.5) / 500),
                150 + ((Math.random() - 0.5) * 10) };
    }
}