2014-05-20 2 views
-3

Je suis en train de construire une application sur la carte google, lorsque je tente de courir suis obtenir erreurgoogle map Impossible de démarrer l'activité ComposantInfo android.view.InflateException: fichier XML binaire ligne # 6: fragment d'erreur de classe gonfler

mais je reçois l'erreur suivante

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 

Activité XML principale

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

MainActivity.java

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) }; 
    } 
} 

Tout corps me s'il vous plaît aider à résoudre ce

+0

S'il vous plaît coûter votre fichier de mise en page et Manifest .. Également poster le logcat .. – Lal

+1

Poster votre MainActivity.java..also ce qui est la ligne n °: 135 dans cela ??? – Lal

+0

poster votre code ... – Dev

Répondre

0

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

Globals

private GoogleMap googleMap; 

Dans onCreate

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

oncreate A l'extérieur, faire une nouvelle méthode _SetMap

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

Xml

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

Dans le fichier manifeste en dehors étiquette d'application définissent

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

et dans la balise d'application manifeste définissent

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

Maintenant

vous devez importer services de jeu de Google dans votre espace de travail sdk/extra/google

+0

oui j'ai fait tous les changements que vous avez dit, mais je reçois toujours la même erreur seulement quand j'essaie de courir – NidhinRaj

+0

avez-vous sur le bouton de googlemap api v2 sur google play console? – Dev

+0

Je ne suis pas en mesure de lancer l'application.J'ai eu une alerte "Malheureusement google map v2 A arrêté" – NidhinRaj

0

MainActivity.java

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) }; 
    } 
} 
Questions connexes