I've been trying to create a Google Maps API v2 app in Eclipse and I keep running into a series of errors that I'm not sure how to solve.
Started coding android apps a few days ago (and coding in general about 2 weeks ago), so it's all still very new to me.
I got my SHA and MD5, my API v2 key, registered it with Google, etc.
I'm not sure where I'm going wrong!
Here's the CatLog upon trying to run as an Android App:
>11-18 16:02:19.756: E/Trace(16453): error opening trace file: No such file or directory (2)
>11-18 16:02:19.756: D/ActivityThread(16453): setTargetHeapUtilization:0.25
>11-18 16:02:19.756: D/ActivityThread(16453): setTargetHeapIdealFree:8388608
>11-18 16:02:19.756: D/ActivityThread(16453): setTargetHeapConcurrentStart:2097152
>11-18 16:02:19.816: W/dalvikvm(16453): threadid=1: thread exiting with uncaught exception (group=0x412b5438)
>11-18 16:02:19.826: E/AndroidRuntime(16453): FATAL EXCEPTION: main
>11-18 16:02:19.826: E/AndroidRuntime(16453): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.deliveryfor/com.deliveryfor.MainActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2081)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2106)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at
android.app.ActivityThread.access$600(ActivityThread.java:138)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1204
)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.os.Handler.dispatchMessage(Handler.java:99)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.os.Looper.loop(Looper.java:137)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.ActivityThread.main(ActivityThread.java:4921)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at java.lang.reflect.Method.invokeNative(Native Method)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at java.lang.reflect.Method.invoke(Method.java:511)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at dalvik.system.NativeStart.main(Native Method)
>11-18 16:02:19.826: E/AndroidRuntime(16453): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:398)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.Activity.setContentView(Activity.java:2087)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.deliveryfor.MainActivity.onCreate(MainActivity.java:24)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.Activity.performCreate(Activity.java:5234)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2045)
>11-18 16:02:19.826: E/AndroidRuntime(16453): ... 11 more
>11-18 16:02:19.826: E/AndroidRuntime(16453): 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" />
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.maps.internal.q.v(Unknown Source)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.maps.internal.q.u(Unknown Source)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.dynamic.a.a(Unknown Source)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.Activity.onCreateView(Activity.java:4889)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
11-18 16:02:19.826: E/AndroidRuntime(16453): ... 21 more
To be honest, I'm not sure how to deduce any solutions from that giant block of red. Here are the elements of my project:
MainActivity:
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends Activity {
private final LatLng LOCATION_STATE = new LatLng(49.27645, -122.917587);
private final LatLng LOCATION_CITY = new LatLng(49.187500, -122.849000);
private final LatLng LOCATION_YOU = new LatLng(49.187500, -122.849000);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
map.addMarker(new MarkerOptions().position(LOCATION_YOU).title("This is you!"));
}
@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;
}
public void onClick_State(View v) {
// CameraUpdate update = CameraUpdateFactory.newLatLng(LOCATION_BURNABY);
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_YOU, 9);
map.animateCamera(update);
}
public void onClick_City(View v) {
map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_CITY, 14);
map.animateCamera(update);
}
public void onClick_You(View v) {
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_STATE, 20);
map.animateCamera(update);
}
}
activity_main.java
<?xml version="1.0" encoding="utf-8"?>
<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" >
<TextView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="@+id/header" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="You"
android:onClick="onClick_You"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:id="@+id/btnYou"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="City"
android:onClick="onClick_City"
android:layout_alignParentTop="true"
android:id="@+id/btnCity"
android:layout_centerHorizontal="true"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="State"
android:onClick="onClick_State"
android:layout_alignParentTop="true"
android:id="@+id/btnState"
android:layout_alignParentLeft="true"/>
</RelativeLayout>
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.deliveryfor"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<uses-permission android:name="com.deliveryfor.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"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:debuggable="true">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBK2qJjm02TrBMNd9eza7PuyRGxWNpxng0"/>
<activity
android:name="com.deliveryfor.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>
To test your application you additionally have to set up the Google Play Services SDK, please refer to this link and add this tag to your manifest file:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Your logcat is pointing to this:
>11-18 16:02:19.826: E/AndroidRuntime(16453): 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" />