Android 在导航抽屉中添加mapview时出错
我犯了一个错误 尝试在空对象引用上调用虚拟方法“voidAndroid 在导航抽屉中添加mapview时出错,android,android-mapview,Android,Android Mapview,我犯了一个错误 尝试在空对象引用上调用虚拟方法“voidcom.google.android.gms.maps.SupportMapFragment.getMapAsync(com.google.android.gms.maps.onmapredyCallback)” 但是我已经按照网站做了所有的事情,我不知道是什么错误,请帮助我在OnViewCreated和used子片段中做了一些事情,而且错误还在继续 请与我们联系 XML 将您的相对值更改为片段 要使用SupportMapFragment,
com.google.android.gms.maps.SupportMapFragment.getMapAsync(com.google.android.gms.maps.onmapredyCallback)”
但是我已经按照网站做了所有的事情,我不知道是什么错误,请帮助我在OnViewCreated和used子片段中做了一些事情,而且错误还在继续
请与我们联系
XML
将您的相对值更改为片段 要使用SupportMapFragment,您始终需要在xml中有一个片段,它可以将其放置在布局中
有关它的更多信息,请参阅
SupportMapFragment
不工作中的安卓片段。。。要解决此问题,请使用MapView
。。
有关在fragment
中使用MapView
的信息,请参见此答案。。。
二进制XML文件行#0:二进制XML文件行#0:膨胀类片段时出错此错误正在弹出您的布局是否仅包含地图?是,它仅包含地图
tools:context=“.MapsActivity”
删除了此行?如果您的布局仅包含映射,则不需要将ConstraintLayout作为xml的根目录,您可以将
作为xml内容only No我没有删除tools:context=“.MapsActivity”相同的错误coming@TanishkAgrawal你还在使用SupportMapFragment吗??
package com.example.tanis.myapplication;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
/**
* A simple {@link Fragment} subclass.
*/
public class ContactUs extends Fragment implements OnMapReadyCallback {
GoogleMap map;
public ContactUs() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate( R.layout.fragment_contact_us, container, false );
return v ;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated( view, savedInstanceState );
SupportMapFragment mapFragment = (SupportMapFragment)getChildFragmentManager().findFragmentById( R.id.map1 );
mapFragment.getMapAsync( this );
}
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
LatLng pp = new LatLng( 28.6403159,77.376114);
MarkerOptions options = new MarkerOptions();
options.position( pp ).title( "WebTechniq" );
map.addMarker( options );
map.moveCamera( CameraUpdateFactory.newLatLng( pp ) );
}
}
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.tanis.myapplication.ContactUs">
<!-- TODO: Update blank fragment layout -->
<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:id="@+id/map1"
tools:context=".MapsActivity"
class="com.google.android.gms.maps.SupportMapFragment" />
</android.support.constraint.ConstraintLayout>