0

setContentView() is giving error in below is my code :

  public class LocateUserInMap extends FragmentActivity {
    private GoogleMap mMap;    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_locate_user_in_map);
         mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
         mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
         final LatLng CIU = new LatLng(19.111693900000000000,72.911271500000000000);
         mMap.addMarker(new MarkerOptions().position(CIU).title("Friend"));
       //  findDirections(19.111693900000000000,72.911271500000000000,19.128203900000000000,72.928065000000060000, GMapV2Direction.MODE_DRIVING);
    }
}

error : enter image description here

here is my library that I am using :
enter image description here

and activity_locate_user_in_map.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=".LocateUserInMap" >

 <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.MapFragment" />

</RelativeLayout>

what I am missing... Please help!!!

Regards,
Sourabh

user2376920
  • 242
  • 1
  • 7
  • 19
  • Post activity_locate_user_in_map.xml – CRUSADER Jul 27 '13 at 06:00
  • it looks like that application cannot find R.layout.activity_locate_user_in_map – Armaan Stranger Jul 27 '13 at 06:02
  • @user2376920 you got solution or not? – Harshid Jul 27 '13 at 06:50
  • no... nothing have worked till yet. – user2376920 Jul 27 '13 at 06:51
  • cleaning of project has not worked. and maps.jar is in GoogleAPI, should I change it to AndroidAPI? – user2376920 Jul 27 '13 at 07:01
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34279/discussion-between-harshid-and-user2376920) – Harshid Jul 27 '13 at 07:02
  • I have referenced to google_play_service_lib and added to build path but it is errored out as `[2013-07-27 16:43:59 - HelpMeRestart] Success! [2013-07-27 16:43:59 - google-play-services_lib] Could not find google-play-services_lib.apk! [2013-07-27 16:43:59 - HelpMeRestart] Starting activity com.example.helpmerestart.Home on device emulator-5554` can you tell where can I find google-play-services_lib.apk file – user2376920 Jul 27 '13 at 11:20
  • @user2376920 Did you find the solution? – f470071 Nov 05 '15 at 07:50

2 Answers2

0

Your layout file R.layout.activity_locate_user_in_map is missing, maybe it is on another project or it is in correct project but somehow it can't be resolved, try to clean the project

Onur A.
  • 3,007
  • 3
  • 22
  • 37
  • apparently com.google.android.gms.maps.MapFragment is missing, take a look at examples at `Android SDK\extras\google\google_play_services\samples\maps` – Onur A. Jul 27 '13 at 07:07
  • I have `MapFragment` in import list of my activity class. – user2376920 Jul 27 '13 at 07:10
  • hımm how about google play services lib ? the example on the path I gave should help – Onur A. Jul 27 '13 at 07:11
  • I have referenced to google_play_service_lib and added to build path but it is errored out as [2013-07-27 16:43:59 - HelpMeRestart] Success! [2013-07-27 16:43:59 - google-play-services_lib] Could not find google-play-services_lib.apk! [2013-07-27 16:43:59 - HelpMeRestart] Starting activity com.example.helpmerestart.Home on device emulator-5554 can you tell where can I find google-play-services_lib.apk file – user2376920 Jul 27 '13 at 11:21
  • hım try with adding the lib .jar file, located at `\extras\google\google_play_services\libproject\google-play-services_lib\bin\google-play-services_lib` – Onur A. Jul 27 '13 at 11:48
  • weird, library projects doesn't include apk files.. are you sure, you referenced the library in right way?http://developer.android.com/google/play-services/setup.html and this one http://developer.android.com/tools/projects/projects-eclipse.html#ReferencingLibraryProject – Onur A. Jul 27 '13 at 12:19
  • is there any share point I can share my code so you can look at this and tell what is missing? – user2376920 Jul 28 '13 at 09:11
  • send it to my mail address, mentioned in my profile, i'll do my best to solve. – Onur A. Jul 28 '13 at 12:18
  • Please get it from [here](https://drive.google.com/folderview?id=0BwCP4NaaWzvHZXJLcmxHSUotMkk&usp=sharing) – user2376920 Jul 29 '13 at 07:00
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34350/discussion-between-user2376920-and-onur-a) – user2376920 Jul 29 '13 at 07:02
0

The @SuppressLint("NewApi") really shouldnt be needed for onCreate() so I am going to guess that you have set your project to the something like:

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

And then are trying to use Fragments without using the support library. You will need to change the imports to something like:

import android.support.v4.app.FragmentActivity;

And change any calls to:

getFragmentManager()

to

getSupportFragmentManager()

You might also like to checkout this question for a good background on Fragment, FragmentActivity and the support lib

Community
  • 1
  • 1
Corey Scott
  • 2,430
  • 3
  • 28
  • 33
  • I have given full code of my class. If i remove `SuppressLint("NewApi")` it says `findFragmentById` requires API11. Also both import are showing warning as never used. and min and max sdk guess is correct. – user2376920 Jul 27 '13 at 06:30
  • Sorry, I don't use library directly but only through ActionBarSherlock so I didn't have code to copy and paste here. I have edited the import part of the answer. Please make sure to remove the current FragmentActivity import – Corey Scott Jul 27 '13 at 06:45
  • **then are trying to use Fragments without using the support library** means? do I need to remove `android-support-v4.jar`. – user2376920 Jul 27 '13 at 06:59
  • If you are going to use fragments without the support lib that you will need to change the to 11+ then you should be gtg – Corey Scott Jul 27 '13 at 07:01
  • Also you can try following this http://www.vogella.com/articles/AndroidGoogleMaps/article.html – Corey Scott Jul 27 '13 at 07:03
  • but above link is using min-sdk = 17 and mine is 8 – user2376920 Jul 27 '13 at 07:07
  • When: android:minSdkVersion=10 or lower (support library is required); for android:minSdkVersion=11 or higher (no need for the support library but you can still use it) – Corey Scott Jul 27 '13 at 07:11
  • yes so I am using support library as androidLminSdkVersion = 8. – user2376920 Jul 27 '13 at 07:17
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34283/discussion-between-user2376920-and-corey-scott) – user2376920 Jul 27 '13 at 07:43
  • I have referenced to google_play_service_lib and added to build path but it is errored out as [2013-07-27 16:43:59 - HelpMeRestart] Success! [2013-07-27 16:43:59 - google-play-services_lib] Could not find google-play-services_lib.apk! [2013-07-27 16:43:59 - HelpMeRestart] Starting activity com.example.helpmerestart.Home on device emulator-5554 can you tell where can I find google-play-services_lib.apk file – user2376920 Jul 27 '13 at 11:21