【发布时间】:2016-02-01 12:22:10
【问题描述】:
我正在开发一个使用片段的应用程序。我想使用谷歌地图的片段之一,但我遇到了错误。
public class Map extends Fragment {
public Map() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
GoogleMap map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
//Error:(38, 84) error: inconvertible types
//required: SupportMapFragment
//found: Fragment
return inflater.inflate(R.layout.fragment_map, container, false);
}
}
当我尝试投射地图片段时,我收到了评论错误。我应该怎么做才能解决这个问题?谢谢大家。 编辑:布局;
<fragment
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment" />
【问题讨论】:
-
它是如何工作的?您在 return 语句之后有代码。
-
在谷歌上搜索。太老的问题了。
-
它对我不起作用。我解决了这个问题(现在返回语句在代码之后但仍然不起作用)
-
发布整个堆栈跟踪。支持库或 vanilla 片段?
标签: android google-maps android-fragments