Autore Topic: Problema Maps API v2.0  (Letto 570 volte)

Offline alessio.p90

  • Nuovo arrivato
  • *
  • Post: 33
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Samsung galaxy SII
  • Sistema operativo:
    Windows 7
Problema Maps API v2.0
« il: 30 Maggio 2014, 22:52:28 CEST »
0
Salve a tutti. Ho già scritto in questo forum qualche fino alla settimana scorsa nella sezione di grafica poichè dovevo sviluppare un'app sulla grafice e mi siete stati davvero utilissimi. Adesso ho un nuovo progetto da portare a termine. Questa volta devo utilizzare le mappe...
Oggi ho iniziato a compiere i primi passi per installare le Maps API v2.0, e tutto ciò che serve di contorno. Ho seguito varie guide in internet passo passo. Ho fatto tutto quello che serviva riguardo la chiave da ottenere per poter utilizzare le mappe ( non so se quello che ho fatto è perfettamente corretto, ma alla fine la key l'ho ottenuta e non mi da nessun errore del genere, quindi...). Il problema è che quando vado ad eseguire l'app sul cellulare, mi crasha riportando un errore che sembra aver a che fare con l'inflate ecc. Vi posto di seguito il codice che ho scritto e il logcat così che possiate aiutarmi a risolvere :D
activity_main.xml
Codice (XML): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical" >

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

MainActivity.java
Codice (Java): [Seleziona]
package com.example.provamaps;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;

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

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 {
            // Loading map
            initilizeMap();
 
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
 
    /**
     * function to load map. If map is not created it will create it for you
     * */

    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();
            }
        }
    }
 
    @Override
    protected void onResume() {
        super.onResume();
        initilizeMap();
    }
   
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
     
      }
 
}

manifest.xml
Codice (XML): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.provamaps"
   android:versionCode="1"
   android:versionName="1.0" >

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

    <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.gms.version"
        android:value="@integer/google_play_services_version" />
        <activity
           android:name="com.example.provamaps.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>
    </application>
   
    <meta-data
       android:name="com.google.android.maps.v2.API_KEY"
      android:value="La mia chiave" />
   
    <permission
       android:name="com.example.provamaps.permission.MAPS_RECEIVE"
       android:protectionLevel="signature" />
   
   
    <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" />

</manifest>

05-30 22:50:00.983: E/AndroidRuntime(22728): FATAL EXCEPTION: main
05-30 22:50:00.983: E/AndroidRuntime(22728): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.provamaps/com.example.provamaps.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.app.ActivityThread.access$700(ActivityThread.java:140)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.os.Looper.loop(Looper.java:137)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.app.ActivityThread.main(ActivityThread.java:4921)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at java.lang.reflect.Method.invokeNative(Native Method)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at java.lang.reflect.Method.invoke(Method.java:511)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at dalvik.system.NativeStart.main(Native Method)
05-30 22:50:00.983: E/AndroidRuntime(22728): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.app.Activity.setContentView(Activity.java:1924)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at com.example.provamaps.MainActivity.onCreate(MainActivity.java:20)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.app.Activity.performCreate(Activity.java:5206)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
05-30 22:50:00.983: E/AndroidRuntime(22728):    ... 11 more
05-30 22:50:00.983: E/AndroidRuntime(22728): Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
05-30 22:50:00.983: E/AndroidRuntime(22728):    at mcg.a(Unknown Source)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at mcg.a(Unknown Source)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at mcg.a(Unknown Source)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at mcg.a(Unknown Source)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at mbi.a(Unknown Source)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at lxn.a(Unknown Source)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at lxm.a(Unknown Source)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at fnb.onTransact(SourceFile:107)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.os.Binder.transact(Binder.java:326)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at com.google.android.gms.dynamic.a$4.b(Unknown Source)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at com.google.android.gms.dynamic.a.a(Unknown Source)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:900)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1184)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
05-30 22:50:00.983: E/AndroidRuntime(22728):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
05-30 22:50:00.983: E/AndroidRuntime(22728):    ... 21 more

Quale diamine è il problema??

Offline Hildian

  • Utente junior
  • **
  • Post: 60
  • Respect: 0
    • Google+
    • Mostra profilo
  • Dispositivo Android:
    Meizu M1 Note
  • Sistema operativo:
    Mac OS X 10.8.5 e Windows 7
Re:Problema Maps API v2.0
« Risposta #1 il: 04 Settembre 2014, 16:24:30 CEST »
0
Prova a scrivere il manifest così

Codice (XML): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.andrea.mapview"
   android:versionCode="1"
   android:versionName="1.0" >

    <uses-sdk
       android:minSdkVersion="11"
       android:targetSdkVersion="21" />
   
    <uses-feature
       android:glEsVersion="0x00020000"
       android:required="true"/>
   
    <permission
      android:name="com.andrea.mapview.permission.MAPS_RECEIVE"
      android:protectionLevel="signature" />
   
    <uses-permission android:name="android.permission.INTERNET"/>
    <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"/>
        <!-- The following two permissions are not required to use
    Google Maps Android API v2, but are recommended. -->
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <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.gms.version"
       android:value="@integer/google_play_services_version" />
       
        <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="il tuo codice"/>
       
        <activity
           android:name=".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>
    </application>

</manifest>