Google Maps v2 - Error
Asked Answered
D

2

0

I have just followed this tutorial (https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2) to present the Google Maps. However, when I try to initialize the application in my phone (ZTE V875) I get an error, or better saying a list of errors. Does anyone know why? Thanks in advance.

In my MainActivity.class I have the following code:

package com.example.tutorialgooglemaps;


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

public class MainActivity extends FragmentActivity {

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

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

}

activity_main.xml

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

Manifest

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

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

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

        <uses-permission android:name="com.example.tutorialgooglemaps.permission.MAPS_RECEIVE"/>
        <uses-permission android:name="android.permission.INTERNET"/>
        <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"/>

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

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

Error output

01-28 18:21:59.219: I/Process(22828): Sending signal. PID: 22828 SIG: 9
01-28 18:22:23.499: E/ActivityThread(22977): >>> handling: 110
01-28 18:22:23.509: D/ActivityThread(22977): <<< done: 110
01-28 18:22:23.509: E/ActivityThread(22977): >>> handling: 100
01-28 18:22:23.519: D/AndroidRuntime(22977): Shutting down VM
01-28 18:22:23.519: W/dalvikvm(22977): threadid=1: thread exiting with uncaught exception (group=0x2aac4560)
01-28 18:22:23.529: E/AndroidRuntime(22977): FATAL EXCEPTION: main
01-28 18:22:23.529: E/AndroidRuntime(22977): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tutorialgooglemaps/com.example.tutorialgooglemaps.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1745)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1761)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.app.ActivityThread.access$1500(ActivityThread.java:124)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:947)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.os.Looper.loop(Looper.java:130)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.app.ActivityThread.main(ActivityThread.java:3822)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at java.lang.reflect.Method.invokeNative(Native Method)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at java.lang.reflect.Method.invoke(Method.java:507)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at dalvik.system.NativeStart.main(Native Method)
01-28 18:22:23.529: E/AndroidRuntime(22977): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.app.Activity.setContentView(Activity.java:1657)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at com.example.tutorialgooglemaps.MainActivity.onCreate(MainActivity.java:11)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1709)
01-28 18:22:23.529: E/AndroidRuntime(22977):    ... 11 more
01-28 18:22:23.529: E/AndroidRuntime(22977): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.tutorialgooglemaps-2.apk]
01-28 18:22:23.529: E/AndroidRuntime(22977):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.view.LayoutInflater.createView(LayoutInflater.java:471)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
01-28 18:22:23.529: E/AndroidRuntime(22977):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
01-28 18:22:23.529: E/AndroidRuntime(22977):    ... 20 more
Densmore answered 28/1, 2013 at 18:33 Comment(5)
I'm not sure, but I think that you can't have Fragment as root-layout.Quintilla
Your code and your crash do not appear to line up. The crash acts as though you are trying to load a layout containing <fragment> from an activity that does not know about <fragment>. Your code, though, is using FragmentActivity, which is correct. The line numbers in the stack trace do not match your supplied code (the trace says you are calling setContentView() on line 11, whereas the pasted code it is not until at least line 13).Strongroom
Thanks GuiceU that was the problem!! I add a <LinearLayout> that contains the <fragment> part and know the code is running perfectly. Thank you all for the replies! :)Densmore
api v2 is deprecated now. you should upgrade to v3Fife
Thanks for the info Rachel. I read about the v3 (developers.google.com/maps/articles/android_v3) but i have one doubt, how can I create the "map" they refer in the 7 point? ThanksDensmore
D
0

If anyone had the same problem, the problem is at the activity_main.xml where a LinearLayout or RelativeLayout is needed. Thanks to everyone

activity_main.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" >


<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" />
</LinearLayout>
Densmore answered 31/1, 2013 at 8:57 Comment(0)
C
0

I commented on a similar problem. Perhaps my answer can also solve your problem!?

google map - runtimeexception - error inflating class fragment

Cordless answered 28/1, 2013 at 18:40 Comment(1)
Thanks, but I have that correctly configured and I'm still getting the errors. I just followed this tutorial to configure the project and import all the libraries. youtube.com/watch?v=mRnEkP2q4fo ThanksDensmore
D
0

If anyone had the same problem, the problem is at the activity_main.xml where a LinearLayout or RelativeLayout is needed. Thanks to everyone

activity_main.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" >


<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" />
</LinearLayout>
Densmore answered 31/1, 2013 at 8:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.