setContentView()给出错误

时间:2013-07-27 05:58:52

标签: android android-library

setContentView()在下面给出的错误是我的代码:

  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);
    }
}

错误: enter image description here

这是我正在使用的图书馆:
enter image description here

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>

我错过了什么...... 请帮忙!!!

的问候,
Sourabh

2 个答案:

答案 0 :(得分:0)

您的布局文件R.layout.activity_locate_user_in_map丢失,可能是在另一个项目上,或者它在正确的项目中,但无论如何都无法解决,请尝试清理项目

答案 1 :(得分:0)

onCreate()确实不需要@SuppressLint(“NewApi”)所以我猜你已经将项目设置为:

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

然后尝试使用片段而不使用support library。 您需要将导入更改为:

import android.support.v4.app.FragmentActivity;

并将所有来电更改为:

getFragmentManager()

getSupportFragmentManager()

您可能还想结帐this question以获得有关Fragment,FragmentActivity和支持库的良好背景

相关问题