2014-01-20 5 views
0

Я пробовал добавлять карты google в свое приложение из разных кодов, но всегда, кажется, получаю сообщение об ошибке. после одного полного дня попыток исправления и другого кода я теряюсь, пожалуйста, помогите мне узнать, почему, когда я нажимаю, чтобы перейти на страницу моих карт, сбой приложений. Я установил его для использования сервисов Google Play и получил свой api-ключ. Я новичок в android, поэтому любая помощь будет отличной.Ошибка Google Map при запуске

журнал кошка:

01-20 11:44:08.417: E/AndroidRuntime(5118): FATAL EXCEPTION: main 
01-20 11:44:08.417: E/AndroidRuntime(5118): Process: com.databasedemo, PID: 5118 
01-20 11:44:08.417: E/AndroidRuntime(5118): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.databasedemo/com.databasedemo.Map}: android.view.InflateException: Binary XML file line #5: Error inflating class fragment 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.os.Handler.dispatchMessage(Handler.java:102) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.os.Looper.loop(Looper.java:136) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.app.ActivityThread.main(ActivityThread.java:5017) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at java.lang.reflect.Method.invokeNative(Native Method) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at java.lang.reflect.Method.invoke(Method.java:515) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at dalvik.system.NativeStart.main(Native Method) 
01-20 11:44:08.417: E/AndroidRuntime(5118): Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class fragment 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.app.Activity.setContentView(Activity.java:1929) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.databasedemo.Map.onCreate(Map.java:27) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.app.Activity.performCreate(Activity.java:5231) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  ... 11 more 
01-20 11:44:08.417: E/AndroidRuntime(5118): Caused by: java.lang.IllegalStateException: The  meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 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" /> 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.google.android.gms.maps.internal.q.v(Unknown Source) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.google.android.gms.maps.internal.q.u(Unknown Source) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.google.android.gms.maps.MapFragment$b.a(Unknown Source) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.google.android.gms.dynamic.a.a(Unknown Source) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.google.android.gms.dynamic.a.onInflate(Unknown Source) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.app.Activity.onCreateView(Activity.java:4785) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689) 
01-20 11:44:08.417: E/AndroidRuntime(5118):  ... 21 more 

мой файл манифеста:

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

<uses-sdk 
    android:minSdkVersion="12" 
    android:targetSdkVersion="18" /> 

<permission android:name="com.image.app.permission.MAPS_RECEIVE" 
android:protectionLevel="signature" /> 
<uses-permission android:name="com.image.app.permission.MAPS_RECEIVE" /> 

<!-- Access Internet --> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
<!-- Take picture --> 
<uses-permission android:name="android.permission.CAMERA" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<!-- GET Latitude Longitude --> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 

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

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

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

    <!-- EVENTS PAGE --> 
    <activity 
     android:name="com.databasedemo.Events" 
     android:label="@string/app_name" 
     > 
     <intent-filter> 
      <action android:name="my.activity.events" /> 

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

    <!-- MAPS PAGE --> 
    <activity 
     android:name="com.databasedemo.Map" 
     android:label="@string/app_name" 
     > 
     <intent-filter> 
      <action android:name="my.activity.map" /> 

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

</application> 

</manifest> 

мой map.java файл

package com.databasedemo; 

import com.databasedemo.R; 
import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 

import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener; 
import com.google.android.gms.maps.MapFragment; 
import com.google.android.gms.maps.model.BitmapDescriptorFactory; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class Map extends FragmentActivity implements OnInfoWindowClickListener 
{ 
    private LatLng defaultLatLng = new LatLng(39.233956, -77.484703); 
    private GoogleMap map; 
    private int zoomLevel = 7; 

    protected void onCreate(Bundle savedInstanceState) 
    { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.map_layout); 


    try { 
     map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)) 
        .getMap(); 
     if (map!=null){ 
      map.getUiSettings().setCompassEnabled(true); 
      map.setTrafficEnabled(true); 
      map.setMyLocationEnabled(true); 


      // Move the camera instantly to defaultLatLng. 
      map.moveCamera(CameraUpdateFactory.newLatLngZoom(defaultLatLng, zoomLevel)); 


      map.addMarker(new MarkerOptions().position(defaultLatLng) 
       .title("This is the title") 
       .snippet("This is the snippet within the InfoWindow") 
       .icon(BitmapDescriptorFactory 
         .fromResource(R.drawable.icon))); 


      map.setOnInfoWindowClickListener(this); 


     } 


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


    } 


    @Override 
    public void onPause() { 
       if (map != null){ 
           map.setMyLocationEnabled(false); 
           map.setTrafficEnabled(false); 
       } 
       super.onPause(); 
    } 



    @Override 
    public void onInfoWindowClick(Marker marker) 
    { 
       Intent intent = new Intent(this, Map.class); 
       intent.putExtra("snippet", marker.getSnippet()); 
       intent.putExtra("title", marker.getTitle()); 
       intent.putExtra("position", marker.getPosition()); 
       startActivity(intent); 
    } 


} 

maplayout.xml файл

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
android:layout_width="match_parent" android:layout_height="match_parent"  android:id="@+id/frame"> 

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

дубликат: http://stackoverflow.com/questions/19723811/after-google-play-service-update-to- version-13-i-got-an-error – laalto

ответ

0

Попробуйте добавить сервисы Google Play версии мета-тег в AndroidMainfest.xml:

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

Это работает, не знал, что вы не можете запустить карту на эмуляторе, хотя .. Примите ответ, как только он позволит мне. – Jayce

Смежные вопросы