我正在开发一个应用程序,它在Android Studio Emulator上运行得很好,但是当我构建APK并安装在手机上时,它关闭并崩溃。所以我决定在我的手机上运行它,用ADB调试。
看起来问题出在该 Java 代码的第 67 行 (https://pastebin.com/y8c5yMYj(
for (int i = 0; i < itemlist.size();i++){
Points item = itemlist.get(i);
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(Double.valueOf(item.getPosx()), Double.valueOf(item.getPosy())))
.snippet(item.getDescription())
.icon(BitmapDescriptorFactory.fromResource(MarkerChange(item.getType())))
.title(item.getName()));
}
..但是我无法解决这个问题,有人可以给我一些帮助解决这个问题吗?
谢谢。。。很抱歉任何发布错误:我是 StackOverflow 的新手,英语不是我的母语。
尚未初始化 ArrayList。编辑代码
public static ArrayList<Points> itemlist;
跟
public static ArrayList<Points> itemlist = new ArrayList<>();
这将解决您的"空指针异常"问题
解决方案:
添加此行是您的onCreateView((
Itemlist = new ArrayList<>();
希望它有效。
像这样更改onCreateView()
。
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.geometry_cube, container, false);
SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager()
.findFragmentById(R.id.mapFragment);
mapFragment.getMapAsync(this);
itemlist = new ArrayList<>();
return v;
}
每次加载该页面时,都需要将ArrayList<>()
声明为新ArrayList