奇怪的例外 [英] Strange exception

查看:188
本文介绍了奇怪的例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我们正在尝试为我们的学期项目制作一个客户端 - 服务器赛车游戏,但我们有一些奇怪的错误

Hey guys we are trying to make a client-server racing game for our semester project but we have some strange error

public void updatePosition(int id, ArrayList<Point2D.Float> positions){
    if(id==1){
        for (int i = 1; i < game.getS().getVehicles().size(); i++)
        {
            game.getS().getVehicles().get(i).updatePosition(positions.get(i));              
        }

    }else if(id==2){
        game.getS().getVehicles().get(1).updatePosition(positions.get(0));              
        for (int i = 2; i < game.getS().getVehicles().size(); i++)
        {
            game.getS().getVehicles().get(i).updatePosition(positions.get(i));  
        }

这是我们的代码

并且异常在这个确切的行中:
game.getS()。getVehicles()。get(1).updatePosition(positions.get(0));

and the exception is in this exact row: game.getS().getVehicles().get(1).updatePosition(positions.get(0));

推荐答案

默认情况下,引用初始化为null。如果创建集合或数组,并且无法初始化引用,则默认情况下它们将为null。

References are initialized to null by default. If you create a collection or array, and fail to initialize references, they'll be null by default.

这篇关于奇怪的例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆