Question

Je suis nouveau dans le développement Android, j'ai commencé avec quelque chose de simple, en affichant simplement une carte centrée sur l'endroit où je vis.J'ai essayé beaucoup de choses pour résoudre mon problème, sans succès, je vais laisser ici mon code et le journal des erreurs.Je serai vraiment reconnaissant si vous pouvez m'aider ;]

Erreur lors du gonflage du fragment de classe:

01-10 03:04:51.632: E/AndroidRuntime(1366): FATAL EXCEPTION: main
01-10 03:04:51.632: E/AndroidRuntime(1366): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.lineapp.tofind/br.com.lineapp.tofind.MapActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.os.Looper.loop(Looper.java:137)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.ActivityThread.main(ActivityThread.java:5103)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at java.lang.reflect.Method.invokeNative(Native Method)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at java.lang.reflect.Method.invoke(Method.java:525)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at dalvik.system.NativeStart.main(Native Method)
01-10 03:04:51.632: E/AndroidRuntime(1366): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.Activity.setContentView(Activity.java:1895)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at br.com.lineapp.tofind.MapActivity.onCreate(MapActivity.java:14)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.Activity.performCreate(Activity.java:5133)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-10 03:04:51.632: E/AndroidRuntime(1366):     ... 11 more
01-10 03:04:51.632: E/AndroidRuntime(1366): 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-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.maps.internal.q.v(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.maps.internal.q.u(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.dynamic.a.a(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.Activity.onCreateView(Activity.java:4745)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
01-10 03:04:51.632: E/AndroidRuntime(1366):     ... 21 more

Activité principale:

package br.com.lineapp.tofind;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
//import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

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

public void verMapa(View v){
    Intent iVerMapa = new Intent(MainActivity.this,MapActivity.class);
        startActivity(iVerMapa);
    }

    /*
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }              */

}

Activité cartographique:

package br.com.lineapp.tofind;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;



public class MapActivity extends FragmentActivity {
@Override

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
}

Mise en page - activité principale:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEE9E9"
 >

<LinearLayout
    android:id="@+id/layoutPrincial"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="50dp">

    <ImageView
        android:id="@+id/mapaLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:src="@drawable/mapa"
        android:layout_marginBottom="20dp" />

    <LinearLayout
        android:id="@+id/layoutBotoes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1"
        android:layout_marginBottom="20dp">

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/map"
            android:background="#00FF7F"
            android:layout_marginBottom="10dp"
            android:onClick="verMapa" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/contatos"
            android:background="#00FF7F"
            android:layout_marginBottom="10dp" />

        <Button
            android:id="@+id/button3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/sair"
            android:background="#00FF7F"
            android:layout_marginBottom="10dp" />
    </LinearLayout>
</LinearLayout>



</RelativeLayout>

mise en page-map_2trouver:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutMap"
android:layout_width="match_parent"
android:layout_height="match_parent"

 >
 <TextView
    android:id="@+id/mano"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

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

</RelativeLayout>

Androidmanifeste

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

<permission
    android:name="br.com.lineapp.tofind.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>

<uses-permission  android:name="br.com.lineapp.tofind.permission.MAPS_RECEIVE"/>
<uses-permission  android:name="android.permission.INTERNET"/>
<uses-permission  android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission  android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission  android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<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"/>

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<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.API_KEY"
        android:value="My_API_KEY"/>

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

    <activity
        android:name="br.com.lineapp.tofind.MapActivity"
        android:label="@string/app_name" >
    </activity>

</application>

</manifest>
Était-ce utile?

La solution

Vérifiez ceci

Une balise de métadonnées requise dans le manifeste Androidman de votre application.xml n'existe pas.

En dehors de cela

<uses-sdk
    android:minSdkVersion="8"

Alors change

 android:name="com.google.android.gms.maps.MapFragment"

à

 android:name="com.google.android.gms.maps.SupportMapFragment"

Supprimez également ceci

<permission
android:name="br.com.lineapp.tofind.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>

et ceci

<uses-permission  android:name="br.com.lineapp.tofind.permission.MAPS_RECEIVE"/>

non requis

Référence:

https://developers.google.com/maps/documentation/android/start

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top