I am trying to display a street view in a fragment.
public class StreetDisplay extends Fragment implements OnStreetViewPanoramaReadyCallback{
SupportStreetViewPanoramaFragment streetFrag;
static final LatLng PosOne = new LatLng(43.771925, -79.512460);
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.street_display, container, false);
initialize();
return v;
}
private void initialize() {
streetFrag =
(SupportStreetViewPanoramaFragment) getFragmentManager()
.findFragmentById(R.id.street);
streetFrag.getStreetViewPanoramaAsync(this);
}
//this method is needed for using a ViewPager swiping feature
public static StreetDisplay newInstance(){
StreetDisplay sd = new StreetDisplay();
return sd;
}
@Override
public void onStreetViewPanoramaReady(StreetViewPanorama panorama) {
panorama.setPosition(PosOne);
}
}
Here's the error message I get when I run my app
Process: com.example.nikhilbhaskar.mapplayground, PID: 22406
java.lang.NullPointerException
at com.example.nikhilbhaskar.mapplayground.StreetDisplay.initialize(StreetDisplay.java:43)
at com.example.nikhilbhaskar.mapplayground.StreetDisplay.onCreateView(StreetDisplay.java:33)
Line 33 is
initialize();
Line 43 is
streetFrag.getStreetViewPanoramaAsync(this);
I am not sure what the problem is - Can you help?
Aucun commentaire:
Enregistrer un commentaire