user2347925
user2347925

Reputation: 3

Android google Map Api V2 Crashes on runtime

I am trying to add a map fragment to an android layout using google map api v2. I have followed several tutorials, even the one google has and has been pointed by a post here. My app crashes after starting the layout. My Files are
Manifest (in [My Key] there is an actual key from Google console using debug code and my package name:

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

    android:versionCode="1"
    android:versionName="1.0" >

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

    <permission
        android:name="com.example.publicthreadsmap.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.publicthreadsmap.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"/>
    <!-- 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"/>

    <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" >
        <uses-library android:name="com.google.android.maps"/>
        <activity
            android:name="com.example.publicthreadsmap.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="[my Key]"/>
        </activity>
    </application>

</manifest>

Layout:

<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"
    tools:context=".MainActivity" >


       <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="23dp"
        android:text="Test" />


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




</RelativeLayout>

and the Java file :

package com.example.publicthreadsmap;

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


public class MainActivity extends FragmentActivity  {

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



}

I have copied (import) the google-play-service-lib in my workspace and referenced it from my map project.
I have also referenced the v4 android support jar.

LogCat massages:
05-04 10:19:56.284: E/AndroidRuntime(21660): FATAL EXCEPTION: main 05-04 10:19:56.284: E/AndroidRuntime(21660): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.publicthreadsmap/com.example.publicthreadsmap.MainActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class fragment 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.app.ActivityThread.access$600(ActivityThread.java:127) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.os.Handler.dispatchMessage(Handler.java:99) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.os.Looper.loop(Looper.java:137) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.app.ActivityThread.main(ActivityThread.java:4507) 05-04 10:19:56.284: E/AndroidRuntime(21660): at java.lang.reflect.Method.invokeNative(Native Method) 05-04 10:19:56.284: E/AndroidRuntime(21660): at java.lang.reflect.Method.invoke(Method.java:511) 05-04 10:19:56.284: E/AndroidRuntime(21660): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:978) 05-04 10:19:56.284: E/AndroidRuntime(21660): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745) 05-04 10:19:56.284: E/AndroidRuntime(21660): at dalvik.system.NativeStart.main(Native Method) 05-04 10:19:56.284: E/AndroidRuntime(21660): Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class fragment 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 05-04 10:19:56.284: E/AndroidRuntime(21660): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:272) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.app.Activity.setContentView(Activity.java:1835) 05-04 10:19:56.284: E/AndroidRuntime(21660): at com.example.publicthreadsmap.MainActivity.onCreate(MainActivity.java:12) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.app.Activity.performCreate(Activity.java:4469) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932) 05-04 10:19:56.284: E/AndroidRuntime(21660): ... 11 more 05-04 10:19:56.284: E/AndroidRuntime(21660): Caused by: java.lang.RuntimeException: API key not found. Check that is in the element of AndroidManifest.xml 05-04 10:19:56.284: E/AndroidRuntime(21660): at maps.z.ab.a(Unknown Source) 05-04 10:19:56.284: E/AndroidRuntime(21660): at maps.z.ab.a(Unknown Source) 05-04 10:19:56.284: E/AndroidRuntime(21660): at maps.z.ab.a(Unknown Source) 05-04 10:19:56.284: E/AndroidRuntime(21660): at maps.z.ag.a(Unknown Source) 05-04 10:19:56.284: E/AndroidRuntime(21660): at maps.z.ag.a(Unknown Source) 05-04 10:19:56.284: E/AndroidRuntime(21660): at maps.z.bw.a(Unknown Source) 05-04 10:19:56.284: E/AndroidRuntime(21660): at maps.z.r.onCreateView(Unknown Source) 05-04 10:19:56.284: E/AndroidRuntime(21660): at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:107) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.os.Binder.transact(Binder.java:297) 05-04 10:19:56.284: E/AndroidRuntime(21660): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source) 05-04 10:19:56.284: E/AndroidRuntime(21660): at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source) 05-04 10:19:56.284: E/AndroidRuntime(21660): at com.google.android.gms.internal.e$4.a(Unknown Source) 05-04 10:19:56.284: E/AndroidRuntime(21660): at com.google.android.gms.internal.e.a(Unknown Source) 05-04 10:19:56.284: E/AndroidRuntime(21660): at com.google.android.gms.internal.e.onCreateView(Unknown Source) 05-04 10:19:56.284: E/AndroidRuntime(21660): at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1066) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1168) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:280) 05-04 10:19:56.284: E/AndroidRuntime(21660): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669) 05-04 10:19:56.284: E/AndroidRuntime(21660): ... 21 more

Upvotes: 0

Views: 2999

Answers (4)

Saravanan
Saravanan

Reputation: 373

Add the following code in manifest file:

 <meta-data
 android:name="com.google.android.gms.version"
 android:value="@integer/google_play_services_version" />

Upvotes: 0

Mehul Joisar
Mehul Joisar

Reputation: 15358

E/AndroidRuntime(21660): ... 11 more 05-04 10:19:56.284: E/AndroidRuntime(21660): Caused by: java.lang.RuntimeException: API key not found. Check that is in the element of AndroidManifest.xml

have a look at how to get api key

and remove <uses-library android:name="com.google.android.maps"/> from manifest,it is used only while dealing with map api v1 which is deprecated now.

Upvotes: 2

Emil Adz
Emil Adz

Reputation: 41139

Your error:

E/AndroidRuntime(21660): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.publicthreadsmap/com.example.publicthreadsmap.MainActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class fragment

indicates that there was a problem inflating class fragment, this usually happens when SupportMapFragment class could not be found. What leads me to think that you did not referenced the google-play-services correctly.

please read the first 3 steps of this blog post and make sure you are doing it's correctly, and you have a green V next to the referencing in the properties window:

Google Map API V2

UPDATE:

Now I see your problem, change this:

 <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.publicthreadsmap.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="[my Key]"/>
    </activity>
</application>

To this:

 <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.publicthreadsmap.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>
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="[my Key]"/>     
</application>

Look carefully at the location of the last activity tag. meta-data tag should appear right before the closing application tag.

Upvotes: 2

Daryn
Daryn

Reputation: 768

Please delete line

<uses-library android:name="com.google.android.maps"/>

from Manifest. If you added necessary jars(google play services, sndroid support v4) and modules, it must work.

Upvotes: 0

Related Questions