Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java “insert”new ClassType()“to complete Expression”是什么意思?_Java_Arrays_Exception - Fatal编程技术网

Java “insert”new ClassType()“to complete Expression”是什么意思?

Java “insert”new ClassType()“to complete Expression”是什么意思?,java,arrays,exception,Java,Arrays,Exception,下面的代码创建了一个对象数组,然后尝试添加一个相同类型的对象 我得到错误语法错误,插入新的类类型来完成表达式 在线 vehicles.[index] = nextVehicle; 但在我看来,这没什么问题。从long到int的转换是否会导致一些问题 long vehicleSize = getVehicleSize(); Vehicle[] vehicles= new Vehicle[(int)vehicleSize]; Vehicle nextVehicle = null; int off

下面的代码创建了一个对象数组,然后尝试添加一个相同类型的对象

我得到错误语法错误,插入新的类类型来完成表达式 在线

vehicles.[index] = nextVehicle;
但在我看来,这没什么问题。从long到int的转换是否会导致一些问题

long vehicleSize = getVehicleSize();

Vehicle[] vehicles= new Vehicle[(int)vehicleSize];
Vehicle nextVehicle = null;
int offSet = 0;
int index= 0;
while (offSet < vehicleSize) {
     nextVeh = new Vehicle(db, offSet);
     vehicles.[index] = nextVehicle;
     index++;
     offSet += nextVehicle.getSize();
}
应该是

vehicles[index] = nextVehicle;

应该是

nextVehicle = new Vehicle(db, offSet);
nextVeh = new Vehicle(db, offSet);
nextVehicle = new Vehicle(db, offSet);