java - Android Google Maps V2 - Project Has Stopped Working -


i'm trying use google android maps v2 on samsung s3 mini (4.1.2) keep on getting message "application has stopped unexpectedly". had included google apis [android 4.1.2], google play services library, android-support-v4.jar. here codes: in androidmanifest.xml

  <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.test.projecttest"     android:versioncode="1"     android:versionname="1.0" >      <permission         android:name="com.test.projecttest.maps_receive"         android:protectionlevel="signature" />      <uses-permission android:name="com.test.projecttest.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" />     <!--      following 2 permissions not required use      google maps android api v2, 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" />      <uses-sdk         android:minsdkversion="11"         android:targetsdkversion="16" />      <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="aizasybjt4hzc4gko1lyrq5fwld_fz5vwguqmla" />          <activity             android:name="com.test.projecttest.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> 

mainactivity.java in com.test.projecttest

      package com.test.projecttest;  import android.app.activity; 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.main);     } } 

main.xml located @ res/layout

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

my logcat:

07-19 16:21:46.594: e/androidruntime(5069): java.lang.runtimeexception: unable start activity componentinfo{com.test.projecttest/com.test.projecttest.mainactivity}: android.view.inflateexception: binary xml file line #2: error inflating class fragment 07-19 16:21:46.594: e/androidruntime(5069): caused by: android.view.inflateexception: binary xml file line #2: error inflating class fragment 07-19 16:21:46.594: e/androidruntime(5069): caused by: android.support.v4.app.fragment$instantiationexception: unable instantiate fragment com.google.android.gms.maps.supportmapfragment: make sure class name exists, public, , has empty constructor public 07-19 16:21:46.594: e/androidruntime(5069): caused by: java.lang.classnotfoundexception: com.google.android.gms.maps.supportmapfragment 

your minsdk 8

 <uses-sdk     android:minsdkversion="8" 

use supportfragment.

use below in layout xml

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

also add manifest

    <permission     android:name="com.test.projecttest.permission.maps_receive"     android:protectionlevel="signature"/>     <uses-permission android:name="com.test.projecttest.permission.maps_receive"/> 

to initialize map object

 supportmapfragment fm = (supportmapfragment)  getsupportfragmentmanager().findfragmentbyid(r.id.map);  googlemap mmap = fm.getmap();  

make sure have added support library

also make sure imported below

import android.support.v4.app.fragmentactivity;   import com.google.android.gms.maps.supportmapfragment;  

Comments