我正在 Android Studio 中创建 GoogleMaps 活动。 我已经从 android studio 生成了默认的 Activity,它生成了以下代码
公共类 MapsActivity 扩展 FragmentActivity 实现 OnMapReadyCallback {
private GoogleMap mMap;
private ActivityMapsBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
当我尝试运行该程序时,它给出了错误
import android.widget.F;
^
symbol: class F
location: package android.widget
在 ActivityMainBinding 中。我也做了以下更改,但错误仍然存在。 在 build.gradle 中我添加了
buildFeatures{
dataBinding = true
viewBinding = true
}
在布局文件中我添加了布局标签
<layout>
<androidx.fragment.app.FragmentContainerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity"
tools:layout="@layout/activity_maps" />
</layout>
如果我添加fragment标签而不是FragmentContainerView,那么它无法找到ActivityMapsBinding类。 谁能更新如何纠正这个问题。
你的导入不完整,没有像
import android.widget.F;
这样的包,你可能错误地添加了它,要解决这个问题,首先删除整行,你的代码中的某个地方应该有一个错误,点击它查看建议,在建议中使用导入,这将导入正确的包。
如果没有解决问题,请添加一些屏幕截图和有关您收到的错误的更多数据,以提供有关问题的更多背景信息