当我尝试创建谷歌地图时,会发生异常错误

时间:2015-03-06 16:29:22

标签: android google-maps gps

如果我尝试在我的设备中创建Google地图,我已经在我的SDK中导入了我的Google Play服务lib文件,然后我尝试运行我的应用程序,但它会显示错误,不幸停止了您的应用,并且日志聊天我将得到以下错误帮我修复此错误

03-06 11:13:48.112: W/dalvikvm(1108): threadid=1: thread exiting with uncaught exception (group=0xb4a7bb90)
03-06 11:13:48.142: E/AndroidRuntime(1108): FATAL EXCEPTION: main
03-06 11:13:48.142: E/AndroidRuntime(1108): Process: com.example.finalmap, PID: 1108
03-06 11:13:48.142: E/AndroidRuntime(1108): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.finalmap/com.example.finalmap.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.app.ActivityThread.access$700(ActivityThread.java:135)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.os.Handler.dispatchMessage(Handler.java:102)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.os.Looper.loop(Looper.java:137)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.app.ActivityThread.main(ActivityThread.java:4998)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at java.lang.reflect.Method.invokeNative(Native Method)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at java.lang.reflect.Method.invoke(Method.java:515)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at dalvik.system.NativeStart.main(Native Method)
03-06 11:13:48.142: E/AndroidRuntime(1108): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.app.Activity.setContentView(Activity.java:1928)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.example.finalmap.MainActivity.onCreate(MainActivity.java:21)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.app.Activity.performCreate(Activity.java:5243)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
03-06 11:13:48.142: E/AndroidRuntime(1108):     ... 11 more
03-06 11:13:48.142: E/AndroidRuntime(1108): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 6587000 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.google.android.gms.common.GooglePlayServicesUtil.D(Unknown Source)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.google.android.gms.maps.internal.x.T(Unknown Source)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.google.android.gms.maps.internal.x.S(Unknown Source)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.google.android.gms.maps.MapFragment$b.nO(Unknown Source)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.google.android.gms.dynamic.a.a(Unknown Source)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.app.Activity.onCreateView(Activity.java:4784)
03-06 11:13:48.142: E/AndroidRuntime(1108):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
03-06 11:13:48.142: E/AndroidRuntime(1108):     ... 21 more
03-06 11:14:10.782: I/Process(1108): Sending signal. PID: 1108 SIG: 9

2 个答案:

答案 0 :(得分:0)

你在谷歌注册你的应用程序了吗?

我认为你没有使用合适的Api键,

如果没有,你必须注册你的应用程序并将你的应用程序的API密钥放在AndroidManifest.xml中。

Register Here

请阅读Google Map API文档。

答案 1 :(得分:0)

我认为您的XML layout以及Setting up the google play service中存在错误,正式文件here

请尝试逐步关注this,最后您的手机上会有地图。

MainAcitivity,示例代码:

public class MainActivity extends Activity {

    private static LatLng goodLatLng = new LatLng(37, -120);
    private GoogleMap googleMap;
    private EditText et_address, et_finalAddress;
    LatLng addressPos, finalAddressPos;
    Marker addressMarker;

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

        et_address = (EditText) findViewById(R.id.addressEditText);
        et_finalAddress = (EditText) findViewById(R.id.finalAddressEditText);


        // Initial Map
        try {

            if (googleMap == null) {
                googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        // Put a dot on my current location
        googleMap.setMyLocationEnabled(true);
        googleMap.setIndoorEnabled(true);
        googleMap.setTrafficEnabled(true);
        // 3D building
        googleMap.setBuildingsEnabled(true);
        // Get zoom button
        googleMap.getUiSettings().setZoomControlsEnabled(true);

        Marker marker = googleMap.addMarker(new MarkerOptions()
                .position(goodLatLng)
                .title("Hello"));
    }

有关详细信息,请参阅我的github here

enter image description here