gpt4 book ai didi

java - java : constructor in class cannot be applied to given types

转载 作者:行者123 更新时间:2023-12-02 11:04:48 25 4
gpt4 key购买 nike

当我尝试使用Maven编译代码时,出现以下错误:

constructor TripGuesser in class TripGuesser cannot be applied to given types

但是在Eclipse(实际上是FuseIDE)中,它不会引发错误!

我的代码是这样的:
public class TripGuesser {
private ArrayList<VehicleAbstract> vehicles;
private DataAccessHandler dataAcces;
private String stop_id;

@SuppressWarnings("unchecked")
public TripGuesser(ArrayList<? extends VehicleAbstract> vehicles, DataAccessHandler dataAccess, String stop_id){
this.vehicles = (ArrayList<VehicleAbstract>) vehicles;
this.dataAcces = dataAccess;
this.stop_id = stop_id;
}
}


public class HelsinkiStopsHandler {
...
ArrayList<Vehicle> vehicles = vehiclesPerRoute.get(routeAndDirectionId);
TripGuesser guesser = new TripGuesser(vehicles, dataAccess, last_stopId);
...
}

public class Vehicle extends VehicleAbstract{
...
}

public abstract class VehicleAbstract{
...
}

我已经尝试过以不同的方式调用构造函数,因此我的类HelsinkiStopsHandler看起来像:
public class HelsinkiStopsHandler  {
ArrayList<? extends VehicleAbstract> vehicles = vehiclesPerRoute.get(routeAndDirectionId);
TripGuesser guesser = new TripGuesser(vehicles, dataAccess, last_stopId);
}

但我仍然遇到相同的错误。

我知道这里有很多熟悉的问题,但是这些答案都不适合我。

Java版本:1.7.0

fuse IDE版本:6.0.0

编译与Maven版本:3.1.0

最佳答案

我找到了解决方案...
它在我的代码如下时起作用:

 public class TripGuesser {
private ArrayList<VehicleAbstract> vehicles;
private DataAccessHandler dataAcces;
private String stop_id;

@SuppressWarnings("unchecked")
public TripGuesser(ArrayList<VehicleAbstract> vehicles, DataAccessHandler dataAccess, String stop_id){
this.vehicles = vehicles;
this.dataAcces = dataAccess;
this.stop_id = stop_id;
}
}


public class HelsinkiStopsHandler {
...
ArrayList<? extends VehicleAbstract> vehicles = vehiclesPerRoute.get(routeAndDirectionId);
ArrayList<VehicleAbstract> vehiclesAbs = (ArrayList<VehicleAbstract>) vehicles;
TripGuesser guesser = new TripGuesser(vehiclesAbs, dataAccess, last_stopId);
...
}

关于java - java : constructor in class cannot be applied to given types,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19766510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com