[GoogleMaps] "error inflating class fragment"
Bonjour tout le monde,
je viens à vous car je bug au tant que l'application sur cette erreur ><.
J'ai comme erreur :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| 11-07 10:35:30.893: E/AndroidRuntime(1197): FATAL EXCEPTION: main
11-07 10:35:30.893: E/AndroidRuntime(1197): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.projetboutique/com.example.projetboutique.MapActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.os.Handler.dispatchMessage(Handler.java:99)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.os.Looper.loop(Looper.java:137)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-07 10:35:30.893: E/AndroidRuntime(1197): at java.lang.reflect.Method.invokeNative(Native Method)
11-07 10:35:30.893: E/AndroidRuntime(1197): at java.lang.reflect.Method.invoke(Method.java:511)
11-07 10:35:30.893: E/AndroidRuntime(1197): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-07 10:35:30.893: E/AndroidRuntime(1197): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-07 10:35:30.893: E/AndroidRuntime(1197): at dalvik.system.NativeStart.main(Native Method)
11-07 10:35:30.893: E/AndroidRuntime(1197): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-07 10:35:30.893: E/AndroidRuntime(1197): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.app.Activity.setContentView(Activity.java:1867)
11-07 10:35:30.893: E/AndroidRuntime(1197): at com.example.projetboutique.MapActivity.onCreate(MapActivity.java:20)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.app.Activity.performCreate(Activity.java:5008)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-07 10:35:30.893: E/AndroidRuntime(1197): ... 11 more
11-07 10:35:30.893: E/AndroidRuntime(1197): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.app.Fragment.instantiate(Fragment.java:584)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.app.Fragment.instantiate(Fragment.java:552)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.app.Activity.onCreateView(Activity.java:4656)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
11-07 10:35:30.893: E/AndroidRuntime(1197): ... 21 more
11-07 10:35:30.893: E/AndroidRuntime(1197): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
11-07 10:35:30.893: E/AndroidRuntime(1197): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-07 10:35:30.893: E/AndroidRuntime(1197): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-07 10:35:30.893: E/AndroidRuntime(1197): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-07 10:35:30.893: E/AndroidRuntime(1197): at android.app.Fragment.instantiate(Fragment.java:574)
11-07 10:35:30.893: E/AndroidRuntime(1197): ... 24 more |
Alors j'ai suivi en grande partie ce tuto -> http://www.androidhive.info/2013/08/...oogle-maps-v2/
Sinon mon activity :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
package com.example.projetboutique;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.widget.Toast;
public class MapActivity extends Activity{
// Google Map
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressLint("NewApi")
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.mapF)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
} |
Son XML
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/mapF"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout> |
Manifest
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.projetboutique"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<permission
android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />
<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/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
//Autres activities...
<activity
android:name="com.example.projetboutique.WebViewActivity"
android:label="@string/title_activity_web_view" >
</activity>
<activity
android:name="com.example.projetboutique.MapActivity"
android:label="MapView" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Goolge Maps API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API CODE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="2"
/>
</application>
</manifest> |
Je dois rajouter une map dans un projet, donc je n'ai pas recréer un nouveau projet et je suis en android 16.
Est-ce que quelqu'un voit le soucis :/?
Cordialement,