将方法推送到队列在Java中不起作用 公共模拟器() { /**要执行自动生成的构造函数stub4*/ dirs=newarraylist(); 对于(int i=0;i
我得到这个错误:将方法推送到队列在Java中不起作用 公共模拟器() { /**要执行自动生成的构造函数stub4*/ dirs=newarraylist(); 对于(int i=0;i,java,Java,我得到这个错误: public Simulator() { /** To do Auto-generated constructor stub4 */ dirs = new ArrayList<LinkedQueue<Vehicle>>(); for (int i = 0; i < 8; ++i) dirs.add(new LinkedQueue<Vehicle>());
public Simulator()
{
/** To do Auto-generated constructor stub4 */
dirs = new ArrayList<LinkedQueue<Vehicle>>();
for (int i = 0; i < 8; ++i)
dirs.add(new LinkedQueue<Vehicle>());
curTime = 0;
countVehicles = 0;
trafficLightsState = 0;
rnd = new Random();
}
/** Add some random vehicles to one of eight available directions and count number of vehicles to be added. */
void addRandomVehicles(int count)
{
for (int i = 0; i < count; ++i)
{
/** do not add if limit is reached */
if (countVehicles == MAX_NUM)
return;
/** choose random direction */
int wh = rnd.nextInt(8);
/** create vehicle on this direction */
Vehicle neww = new Vehicle(countVehicles + 1, curTime,
Vehicle.Street.values()[wh / 4], Vehicle.Directiron.values()[wh / 2]);
/* add to corresponding queue */
dirs.get(wh).push(neww);
countVehicles++;
}
}
Simulator.java:78:找不到符号
符号:方法添加(车辆)
位置:类java.util.ArrayList
直接添加(新建);
^
Simulator.java:105:找不到符号
符号:方法pop()
位置:类jsjf.LinkedQueue
车辆电流=dirs.get(j.pop();
^
2个错误
你知道我在这里遗漏了什么吗?你已经声明了jsjf的ArrayList.LinkedQueue不是车辆的ArrayList。这些都是你在那里发现的一些非常清楚和简洁的编译器错误。哪一点让你感到悲伤?我不相信你发布了相关代码。我是Java新手,你能帮我吗?发布发生错误的第78行和第105行的代码。
Simulator.java:78: cannot find symbol
symbol : method add(Vehicle)
location: class java.util.ArrayList<jsjf.LinkedQueue<Vehicle>>
dirs.add(neww);
^
Simulator.java:105: cannot find symbol
symbol : method pop()
location: class jsjf.LinkedQueue<Vehicle>
Vehicle cur = dirs.get(j).pop();
^
2 errors