无法摆脱错误膨胀类片段错误



我正在尝试在我的应用程序中显示谷歌地图中的一些点。所以我尝试了下面的代码来实现这一点:

public class MessageDetailsActivity extends FragmentActivity implements OnMapReadyCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message_details);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.googleMap);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
Long latitude   = getIntent().getLongExtra("latitude",0);
Long longtitude = getIntent().getLongExtra("longtitude", 0);
googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longtitude)).title("Marker"));
}
}

这是我activity_message_details.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/datetime"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<fragment
android:id="@+id/googleMap"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>

我在setContectView部分中遇到了Error inflating class fragment错误。我知道类似的问题被问了很多次,我在stackoverflow中查看了有关此主题的所有主题,但无法摆脱它。

还有一件事。我可以在弹出窗口中显示带有标记的地图,而不是打开新活动吗?而且我还需要添加一些文本视图来弹出。有可能做到吗?

GoogleMap mMap;
SupportMapFragment mMapFragment;
if (mMap == null) {
mMapFragment= (SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.googleMap);
mMap =  mMapFragment.getMap();
if (mMap != null) {
}
}

实际上我的问题是关于 API 密钥的。将 API 密钥添加到清单文件后,在应用程序标记之外,它解决了:

<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCv0EKZ7WxirSW0V-lrUI6zKt-8hl5QwRU" />