Java 通过传递latlong更新Google地图位置,构造函数抛出空点异常

Java 通过传递latlong更新Google地图位置,构造函数抛出空点异常,java,android,google-maps,android-fragments,Java,Android,Google Maps,Android Fragments,我正在使用带有actionbar选项卡片段的google maps v2。一切都很好,但我需要更新我的地图位置,从第一个标签第一个片段传递lat long,因为地图在第二个标签上。我通过构造器通过拉特朗。 首先,问题是如何处理viewpager上片段的生命周期,但通过遵循教程,问题得到了解决。现在我在onFragmentPause中使用map Update方法,但它会引发空点异常。如果我将它放在onViewCreate中,它仍然可以正常工作。创建详细显示的代码 跟踪片段: 现在,如果我将Setu

我正在使用带有actionbar选项卡片段的google maps v2。一切都很好,但我需要更新我的地图位置,从第一个标签第一个片段传递lat long,因为地图在第二个标签上。我通过构造器通过拉特朗。 首先,问题是如何处理viewpager上片段的生命周期,但通过遵循教程,问题得到了解决。现在我在onFragmentPause中使用map Update方法,但它会引发空点异常。如果我将它放在onViewCreate中,它仍然可以正常工作。创建详细显示的代码

跟踪片段:

现在,如果我将SetupMapiFneed放入onCreateView并更改旋转,它将重新创建并更新位置,但放入onResumeFragment时出错。 请帮助我,如果我不能有效地描述,请道歉

错误 因为logcat在第48行显示错误。就是 .findFragmentByIdR.id.location_map.getMap

这是活动轨道


datahandler为null,因为它是垃圾收集的,您需要将数据存储在其他情况下,如果我再次静态地给出latlong,则会给出相同的错误。那么,在01-28 18:34:51.146:E/AndroidRuntime1710:FATAL异常:main 01-28 18:34:51.146:E/AndroidRuntime1710:java.lang.NullPointerException 01-28 18:34:51.146:E/AndroidRuntime1710:at com.upanels.edrivetrackingapp.Track.onResumeFragmentTrack.java:83@tyczj plz上发生的错误是哪一行检查该选项不会告诉我是什么导致了问题
public class Track extends Fragment implements FragmentLifecycle {
private static GoogleMap mMap;
private static Double latitude, longitude;
private static String vAddress;
private static View Track;
DataHandler dh;

@Override 
public void onAttach(Activity activity) {
    super.onAttach(activity);
    if(activity instanceof DataHandler)
    {
        dh = (DataHandler)activity;
    }
    else
        throw new ClassCastException();

}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    Track  = inflater.inflate(R.layout.activity_track, container, false);

    return Track;
}

public void setUpMapIfNeeded() {
        // Try to obtain the map from the SupportMapFragment.
        mMap = ((SupportMapFragment) getFragmentManager()
                .findFragmentById(R.id.location_map)).getMap();
        setUpMap();
}

private static void setUpMap() {
    try{
    mMap.setMyLocationEnabled(true);
    mMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title(vAddress).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker2)));
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,
            longitude), 12.0f));
    }
    catch(Exception e){
        Log.wtf("this error", "ok");
    }
}

public void onDestroyView() {
    super.onDestroyView();

    try {
        Fragment fragment = (getFragmentManager().findFragmentById(R.id.location_map));  
        FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
        ft.remove(fragment);
        ft.commit();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
@Override
public void onPauseFragment() {

}
@Override
public void onResumeFragment() {
    Log.i("state", "onResumeFragment()");
    latitude= 73.023333; //getting latitude from first tab(fragment)by calling constructor 
    longitude= 67.939322;
    vAddress = "some address";
    setUpMapIfNeeded();
}
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
         <fragment
        android:id="@+id/location_map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

</LinearLayout>
@Override
    public void onResumeFragment() {
        Log.i("state", "onResumeFragment()");
        latitude= dh.getLat(); //getting latitude from first tab(fragment)by calling constructor 
        longitude= dh.getLong();
        vAddress = dh.getAddress();
        setUpMap();
    }