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
<fragment>
from an activity that does not know about<fragment>
. Your code, though, is usingFragmentActivity
, which is correct. The line numbers in the stack trace do not match your supplied code (the trace says you are callingsetContentView()
on line 11, whereas the pasted code it is not until at least line 13). – Strongroom