Reputation: 115
I can't load the basic google map v2 in my phone.
I do the coding according to this Website and i got my api key.
but the program still didn't work.this give the below error
error
07-22 13:02:24.630: E/AndroidRuntime(5323): FATAL EXCEPTION: main
07-22 13:02:24.630: E/AndroidRuntime(5323): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemap/com.example.googlemap.MainActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.os.Looper.loop(Looper.java:130)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.app.ActivityThread.main(ActivityThread.java:3691)
07-22 13:02:24.630: E/AndroidRuntime(5323): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 13:02:24.630: E/AndroidRuntime(5323): at java.lang.reflect.Method.invoke(Method.java:507)
07-22 13:02:24.630: E/AndroidRuntime(5323): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
07-22 13:02:24.630: E/AndroidRuntime(5323): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
07-22 13:02:24.630: E/AndroidRuntime(5323): at dalvik.system.NativeStart.main(Native Method)
07-22 13:02:24.630: E/AndroidRuntime(5323): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-22 13:02:24.630: E/AndroidRuntime(5323): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:235)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.app.Activity.setContentView(Activity.java:1663)
07-22 13:02:24.630: E/AndroidRuntime(5323): at com.example.googlemap.MainActivity.onCreate(MainActivity.java:11)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
07-22 13:02:24.630: E/AndroidRuntime(5323): ... 11 more
07-22 13:02:24.630: E/AndroidRuntime(5323): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.googlemap-1.apk]
07-22 13:02:24.630: E/AndroidRuntime(5323): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
07-22 13:02:24.630: E/AndroidRuntime(5323): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
07-22 13:02:24.630: E/AndroidRuntime(5323): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
07-22 13:02:24.630: E/AndroidRuntime(5323): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
07-22 13:02:24.630: E/AndroidRuntime(5323): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
07-22 13:02:24.630: E/AndroidRuntime(5323): ... 20 more
manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission android:name = "com.examaple.googlemap.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name ="com.example.googlemap.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" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAc8wx3VIrczUu7yG6XL1P5rFHLpz3Do2Q"/>
<activity
android:name="com.example.googlemap.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>
Layout :- activity_main.xml
<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"
android:text="@string/hello_world" />
<fragment
android:id="@+id/map"
android:layout_below="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Upvotes: 1
Views: 301
Reputation: 133560
Your min sdk in 8. You should use SupportMapFragment
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Your activity must extend FragmentActivity
.
Make sure you have added support library
Also make sure you imported the below
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;
Make sure you have referenced the google play services library project.
You can download it from the sdk manager and follow the suggestion in the below link.
Importing google-play-service library showing a red X next to this reference android
As a side note if you have updated ADT to rev 22 make sure you check Android private libraries in oerder export tab of java build path.Clean and build. Ignore this if not required.
Also make sure you have enabled google maps for android in the services tab of gogle api console.
Upvotes: 1