我试图在片段中显示街景。NullPointerException - 安卓谷歌地图街景
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);
}
}
这里的错误消息时我跑我的应用程序,我得到
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)
管线33
initialize();
第43行是
streetFrag.getStreetViewPanoramaAsync(this);
我不知道是什么问题是 - 你能帮忙吗?
对'Fragment'使用支持库吗? – Josef 2015-02-24 22:16:58
你是这个意思?导入android.support.v4.app.Fragment;是的,这是我从 – 2015-02-24 22:24:07
扩展的片段类尝试更改此:'getFragmentManager()'为:'getSupportFragmentManager()' – Josef 2015-02-24 22:28:09