Autore Topic: Problema visualizzazione mappa  (Letto 3535 volte)

Offline bakiko

  • Utente junior
  • **
  • Post: 74
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    HTC One
  • Sistema operativo:
    Windows 7
Problema visualizzazione mappa
« il: 03 Febbraio 2014, 20:26:55 CET »
0
Salve ragazzi ho un semplice problema con le mappe di google.
Ho seguito questa guida per ottenere le google Map Key: Google Maps Android API v2 - Tutorial
dopodichè l'ho importata nel progetto.
La mia app deve semplicemente visualizzare la mappa (sarebbe proprio il primo passo).
Questo è il manifest:
Codice (Java): [Seleziona]
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mygooglemaps"
    android:versionCode="1"
    android:versionName="1.0" >

    <permission
        android:name="com.example.mygooglemaps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.mygooglemaps.permission.MAPS_RECEIVE" />

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.mygooglemaps.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>
       
         <!-- Goolge API Key -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="xxxxxxxxxxxxxxxxxxxxxxxx" />
       
    </application>
</manifest>

Questa invece è la mia activity:
Codice (Java): [Seleziona]
public class MainActivity extends Activity {

        static final LatLng HAMBURG = new LatLng(53.558, 9.927);
          static final LatLng KIEL = new LatLng(53.551, 9.993);
          private GoogleMap map;
       
        @SuppressLint("NewApi")
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                 map = ((MapFragment)this.getFragmentManager().findFragmentById(R.id.map)).getMap();
                           
                            if (map!=null){
                              Marker marco = map.addMarker(new MarkerOptions().position(MARCO)
                                  .title("Posizione di Marco"));
                              Marker kiel = map.addMarker(new MarkerOptions()
                                  .position(MIA)
                                  .title("Mia posizione")
                                  .snippet("Sto qua")
                                  .icon(BitmapDescriptorFactory
                                      .fromResource(R.drawable.ic_launcher)));
                            }
                            map.moveCamera(CameraUpdateFactory.newLatLngZoom(MARCO, 15));

                            // Zoom in, animating the camera.
                            map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
        }

Questo è il mio main.xml:
Codice (Java): [Seleziona]
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

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

</RelativeLayout>

Questo invece è il logcat:
Codice (Java): [Seleziona]
02-03 20:19:30.042: E/AndroidRuntime(22062): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mygooglemaps/com.example.mygooglemaps.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.app.ActivityThread.access$700(ActivityThread.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.os.Handler.dispatchMessage(Handler.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.os.Looper.loop(Looper.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.app.ActivityThread.main(ActivityThread.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at java.lang.reflect.Method.invokeNative(Native Method)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at java.lang.reflect.Method.invoke(Method.java:515)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at dalvik.system.NativeStart.main(Native Method)
02-03 20:19:30.042: E/AndroidRuntime(22062): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.view.LayoutInflater.rInflate(LayoutInflater.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.view.LayoutInflater.inflate(LayoutInflater.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:547)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.view.LayoutInflater.inflate(Native Method)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.view.LayoutInflater.inflate(LayoutInflater.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.view.LayoutInflater.inflate(LayoutInflater.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.app.Activity.setContentView(Activity.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.example.mygooglemaps.MainActivity.onCreate(MainActivity.java:28)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.app.Activity.performCreate(Activity.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    ... 13 more
02-03 20:19:30.042: E/AndroidRuntime(22062): 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" />
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.google.android.gms.maps.internal.q.v(Unknown Source)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.google.android.gms.maps.internal.q.u(Unknown Source)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.google.android.gms.dynamic.a.a(Unknown Source)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
02-03 20:19:30.042: E/AndroidRuntime(22062):    at android.app.Activity.onCreateView(Activity.java)
02-03 20:19:30.042: E/AndroidRuntime(22062):    ... 26 more

Non riesco proprio a capire se ci sia un errore nel file xml o altro.Eppure credo di aver seguito la guida :(... Grazie a tutti

Offline Reinhard

  • Utente junior
  • **
  • Post: 85
  • Respect: +16
    • Google+
    • rspisser
    • Mostra profilo
  • Dispositivo Android:
    Nexus 5 Lollipop 5.1
  • Play Store ID:
    rspisser
  • Sistema operativo:
    Windows 7
Re:Problema visualizzazione mappa
« Risposta #1 il: 03 Febbraio 2014, 23:14:35 CET »
0
a prima vista sembra che manca

Codice (XML): [Seleziona]
<uses-feature
       android:glEsVersion="0x00020000"
       android:required="true" />

nel AndroidManifest.xml
« Ultima modifica: 04 Febbraio 2014, 10:00:06 CET da Reinhard »

Offline crc_error

  • Utente junior
  • **
  • Post: 85
  • Respect: +8
    • Mostra profilo
  • Dispositivo Android:
    LG-P500
  • Sistema operativo:
    Windows 8, Ubuntu 12
Re:Problema visualizzazione mappa
« Risposta #2 il: 03 Febbraio 2014, 23:54:10 CET »
0
Sembra che nel manifest dentro il tag <application> manchi anche:

Codice (XML): [Seleziona]
   <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

Offline bakiko

  • Utente junior
  • **
  • Post: 74
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    HTC One
  • Sistema operativo:
    Windows 7
Re:Problema visualizzazione mappa
« Risposta #3 il: 04 Febbraio 2014, 14:30:26 CET »
0
Ragazzi io non so davvero come farei senza di voi... Grazieeeeeeeee :D
Tutto Risolto


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

    <permission
        android:name="com.example.mygooglemaps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.mygooglemaps.permission.MAPS_RECEIVE" />

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

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

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

        <!-- Goolge API Key -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>

</manifest>

Offline ilthebest

  • Nuovo arrivato
  • *
  • Post: 26
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Samsung Galaxy Nexus
  • Sistema operativo:
    Windows 8.1
Re:Problema visualizzazione mappa
« Risposta #4 il: 13 Febbraio 2014, 12:54:19 CET »
0
Ho lo stesso problema e non riesco a risolverlo.

Logcat

Codice: [Seleziona]
02-13 12:51:52.704: E/AndroidRuntime(14057): FATAL EXCEPTION: main
02-13 12:51:52.704: E/AndroidRuntime(14057): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.guestbook/com.example.guestbook.visuaMappa}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment

XML

Codice (XML): [Seleziona]
<?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"
         android:name="com.google.android.gms.maps.SupportMapFragment"/>

Manifest

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

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<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="9"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:name="com.google.android.maps" />
       
        <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="AIzaSyCa0QOsqd_JT4mCt2cGSAa2mNAobDns62w"/>
        <activity
            android:name="com.example.guestbook.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="com.example.guestbook.NewCommentActivity">
         </activity>
         <activity
           android:name="com.example.guestbook.visuaMappa">
         </activity>
    </application>

</manifest>


Java

Codice (Java): [Seleziona]
package com.example.guestbook;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

public class visuaMappa extends FragmentActivity {
       
       

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

idee?
Grazie
« Ultima modifica: 13 Febbraio 2014, 12:55:59 CET da ilthebest »
L'arte è un lavoro sporco, ma qualcuno lo deve pur fare!

CTRL + SHIFT + O: vi risolverà molti problemi!

Offline Reinhard

  • Utente junior
  • **
  • Post: 85
  • Respect: +16
    • Google+
    • rspisser
    • Mostra profilo
  • Dispositivo Android:
    Nexus 5 Lollipop 5.1
  • Play Store ID:
    rspisser
  • Sistema operativo:
    Windows 7
Re:Problema visualizzazione mappa
« Risposta #5 il: 13 Febbraio 2014, 13:49:16 CET »
0
devi includere il fragment in un Layout

Codice (XML): [Seleziona]
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:paddingBottom="@dimen/activity_vertical_margin"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   tools:context=".MainActivity" >

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

</RelativeLayout>

Offline ilthebest

  • Nuovo arrivato
  • *
  • Post: 26
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Samsung Galaxy Nexus
  • Sistema operativo:
    Windows 8.1
Re:Problema visualizzazione mappa
« Risposta #6 il: 13 Febbraio 2014, 17:40:27 CET »
0
Purtroppo crasha ancora...
La riga 11 del file xml si trova in corrispondenza di "<fragment ..."

Codice: [Seleziona]
02-13 17:39:04.379: E/AndroidRuntime(18624): FATAL EXCEPTION: main
02-13 17:39:04.379: E/AndroidRuntime(18624): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.guestbook/com.example.guestbook.visuaMappa}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.os.Handler.dispatchMessage(Handler.java:99)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.os.Looper.loop(Looper.java:137)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.app.ActivityThread.main(ActivityThread.java:5103)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at java.lang.reflect.Method.invokeNative(Native Method)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at java.lang.reflect.Method.invoke(Method.java:525)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at dalvik.system.NativeStart.main(Native Method)
02-13 17:39:04.379: E/AndroidRuntime(18624): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.app.Activity.setContentView(Activity.java:1895)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at com.example.guestbook.visuaMappa.onCreate(visuaMappa.java:15)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.app.Activity.performCreate(Activity.java:5133)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
02-13 17:39:04.379: E/AndroidRuntime(18624):         ... 11 more
02-13 17:39:04.379: E/AndroidRuntime(18624): 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
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.app.Fragment.instantiate(Fragment.java:592)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.app.Fragment.instantiate(Fragment.java:560)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.app.Activity.onCreateView(Activity.java:4738)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
02-13 17:39:04.379: E/AndroidRuntime(18624):         ... 21 more
02-13 17:39:04.379: E/AndroidRuntime(18624): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.guestbook-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.guestbook-2, /vendor/lib, /system/lib]]
02-13 17:39:04.379: E/AndroidRuntime(18624):         at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-13 17:39:04.379: E/AndroidRuntime(18624):         at android.app.Fragment.instantiate(Fragment.java:582)
02-13 17:39:04.379: E/AndroidRuntime(18624):         ... 24 more
L'arte è un lavoro sporco, ma qualcuno lo deve pur fare!

CTRL + SHIFT + O: vi risolverà molti problemi!

Offline ilthebest

  • Nuovo arrivato
  • *
  • Post: 26
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Samsung Galaxy Nexus
  • Sistema operativo:
    Windows 8.1
Re:Problema visualizzazione mappa
« Risposta #7 il: 14 Febbraio 2014, 18:29:28 CET »
0
Ho risolto avevo sbagliato a mettere dentro al file integers.xml il valore di google_play_services_version
L'arte è un lavoro sporco, ma qualcuno lo deve pur fare!

CTRL + SHIFT + O: vi risolverà molti problemi!

Offline felasandroid

  • Utente normale
  • ***
  • Post: 345
  • Respect: +10
    • Github
    • balduzziantonio
    • balduzziantonio.unifi
    • Mostra profilo
  • Dispositivo Android:
    Huawei P8 Lite
  • Play Store ID:
    FelasTech
  • Sistema operativo:
    Windows 10
Re:Problema visualizzazione mappa
« Risposta #8 il: 02 Marzo 2014, 16:21:45 CET »
0
stesso problema ma mi pare di aver messo tutto:

Manifest
Codice (Java): [Seleziona]
<?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="12"
        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>

        <!-- Goolge API Key -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyCY93dhSD2Ckw1jud6HJaNrH36si-v6gfw" />
        <meta-data
            android:name="com.google.android.gms.version"
          android:value="@integer/google_play_services_version" />
       
    </application>

</manifest>

poi Layout:

Codice (Java): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

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

</RelativeLayout>


poi FragmentActivity:

Codice (Java): [Seleziona]
package info.androidhive.googlemapsv2;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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.SupportMapFragment;

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 {
                        // Loading map
                        initilizeMap();

                        // Changing map type
                        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                        // googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
                        // googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
                        // googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
                        // googleMap.setMapType(GoogleMap.MAP_TYPE_NONE);

                        // Showing / hiding your current location
                        googleMap.setMyLocationEnabled(true);

                        // Enable / Disable zooming controls
                        googleMap.getUiSettings().setZoomControlsEnabled(false);

                        // Enable / Disable my location button
                        googleMap.getUiSettings().setMyLocationButtonEnabled(true);

                        // Enable / Disable Compass icon
                        googleMap.getUiSettings().setCompassEnabled(true);

                        // Enable / Disable Rotate gesture
                        googleMap.getUiSettings().setRotateGesturesEnabled(true);

                        // Enable / Disable zooming functionality
                        googleMap.getUiSettings().setZoomGesturesEnabled(true);

                        double latitude = 17.385044;
                        double longitude = 78.486671;

                        // lets place some 10 random markers
                        for (int i = 0; i < 10; i++) {
                                // random latitude and logitude
                                double[] randomLocation = createRandLocation(latitude,
                                                longitude);

                                // Adding a marker
                                MarkerOptions marker = new MarkerOptions().position(
                                                new LatLng(randomLocation[0], randomLocation[1]))
                                                .title("Hello Maps " + i);

                                Log.e("Random", "> " + randomLocation[0] + ", "
                                                + randomLocation[1]);

                                // changing marker color
                                if (i == 0)
                                        marker.icon(BitmapDescriptorFactory
                                                        .defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
                                if (i == 1)
                                        marker.icon(BitmapDescriptorFactory
                                                        .defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
                                if (i == 2)
                                        marker.icon(BitmapDescriptorFactory
                                                        .defaultMarker(BitmapDescriptorFactory.HUE_CYAN));
                                if (i == 3)
                                        marker.icon(BitmapDescriptorFactory
                                                        .defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
                                if (i == 4)
                                        marker.icon(BitmapDescriptorFactory
                                                        .defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
                                if (i == 5)
                                        marker.icon(BitmapDescriptorFactory
                                                        .defaultMarker(BitmapDescriptorFactory.HUE_ORANGE));
                                if (i == 6)
                                        marker.icon(BitmapDescriptorFactory
                                                        .defaultMarker(BitmapDescriptorFactory.HUE_RED));
                                if (i == 7)
                                        marker.icon(BitmapDescriptorFactory
                                                        .defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
                                if (i == 8)
                                        marker.icon(BitmapDescriptorFactory
                                                        .defaultMarker(BitmapDescriptorFactory.HUE_VIOLET));
                                if (i == 9)
                                        marker.icon(BitmapDescriptorFactory
                                                        .defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));

                                googleMap.addMarker(marker);

                                // Move the camera to last position with a zoom level
                                if (i == 9) {
                                        CameraPosition cameraPosition = new CameraPosition.Builder()
                                                        .target(new LatLng(randomLocation[0],
                                                                        randomLocation[1])).zoom(15).build();

                                        googleMap.animateCamera(CameraUpdateFactory
                                                        .newCameraPosition(cameraPosition));
                                }
                        }

                } 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 initilizeMap() {
                if (googleMap == null) {
                       
                        SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map);
            googleMap = fm.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) };
        }
}

Offline ilthebest

  • Nuovo arrivato
  • *
  • Post: 26
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Samsung Galaxy Nexus
  • Sistema operativo:
    Windows 8.1
Re:Problema visualizzazione mappa
« Risposta #9 il: 02 Marzo 2014, 17:06:18 CET »
0
posta il LogCat
L'arte è un lavoro sporco, ma qualcuno lo deve pur fare!

CTRL + SHIFT + O: vi risolverà molti problemi!

Offline felasandroid

  • Utente normale
  • ***
  • Post: 345
  • Respect: +10
    • Github
    • balduzziantonio
    • balduzziantonio.unifi
    • Mostra profilo
  • Dispositivo Android:
    Huawei P8 Lite
  • Play Store ID:
    FelasTech
  • Sistema operativo:
    Windows 10
Re:Problema visualizzazione mappa
« Risposta #10 il: 02 Marzo 2014, 17:07:44 CET »
0
posta il LogCat


Codice (Java): [Seleziona]
03-02 17:06:29.365: E/AndroidRuntime(9438): FATAL EXCEPTION: main
03-02 17:06:29.365: E/AndroidRuntime(9438): java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.googlemapsv2/info.androidhive.googlemapsv2.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.os.Looper.loop(Looper.java:137)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.app.ActivityThread.main(ActivityThread.java:4898)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at java.lang.reflect.Method.invokeNative(Native Method)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at java.lang.reflect.Method.invoke(Method.java:511)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at dalvik.system.NativeStart.main(Native Method)
03-02 17:06:29.365: E/AndroidRuntime(9438): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.app.Activity.setContentView(Activity.java:1924)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at info.androidhive.googlemapsv2.MainActivity.onCreate(MainActivity.java:28)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.app.Activity.performCreate(Activity.java:5206)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-02 17:06:29.365: E/AndroidRuntime(9438):     ... 11 more
03-02 17:06:29.365: E/AndroidRuntime(9438): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
03-02 17:06:29.365: E/AndroidRuntime(9438):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-02 17:06:29.365: E/AndroidRuntime(9438):     ... 21 more

Post unito: 02 Marzo 2014, 17:10:16 CET
appena risolto, praticamente ho sostituito Activity al posto di FragmentActiviry e messo
import android.app.Fragment;
« Ultima modifica: 02 Marzo 2014, 17:10:16 CET da felasandroid, Reason: Merged DoublePost »

Offline tank

  • Nuovo arrivato
  • *
  • Post: 23
  • Respect: 0
    • Mostra profilo
Re:Problema visualizzazione mappa
« Risposta #11 il: 18 Giugno 2014, 12:47:28 CEST »
0
Ho risolto avevo sbagliato a mettere dentro al file integers.xml il valore di google_play_services_version
Ho lo stesso problema anch'io, prima di postare codice e logcat sto prima provando tutti i suggerimenti dati fin'ora.
Mi puoi dire dove si trova precisamente il file integers.xml?

Offline ilthebest

  • Nuovo arrivato
  • *
  • Post: 26
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Samsung Galaxy Nexus
  • Sistema operativo:
    Windows 8.1
Re:Problema visualizzazione mappa
« Risposta #12 il: 18 Giugno 2014, 13:35:32 CEST »
0
Dopo aver aperto Eclipse nella colonna di SX apri il progetto e vai nel seguente percorso:

NomeProgetto -> res -> values -> integers.xml
L'arte è un lavoro sporco, ma qualcuno lo deve pur fare!

CTRL + SHIFT + O: vi risolverà molti problemi!

Offline tank

  • Nuovo arrivato
  • *
  • Post: 23
  • Respect: 0
    • Mostra profilo
Re:Problema visualizzazione mappa
« Risposta #13 il: 18 Giugno 2014, 14:19:14 CEST »
0
Non c'è .-. né nel mio progetto né nella libreria Google. Ho trovato solo qualcosa di analogo tipo version.xml (nella cartella values della libreria Google) che contiene:
Codice (XML): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="google_play_services_version">4452000</integer>
</resources>

Offline ilthebest

  • Nuovo arrivato
  • *
  • Post: 26
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Samsung Galaxy Nexus
  • Sistema operativo:
    Windows 8.1
Re:Problema visualizzazione mappa
« Risposta #14 il: 18 Giugno 2014, 14:52:58 CEST »
0
Va bene lo stesso.
L'arte è un lavoro sporco, ma qualcuno lo deve pur fare!

CTRL + SHIFT + O: vi risolverà molti problemi!