我有这个方法:
public Route getSubroute(int startOffset, int endOffset) {
if (!(0 <= startOffset && startOffset < endOffset && endOffset <= this
.getLength())) {
throw new IllegalArgumentException("Subroute is out of bounds.");
}
// the sub-segments that will make up the sub-route
List<Segment> subsegments = new ArrayList<>();
// variable offset is the distance along the route to the start of the
// segment currently being examined
int offset = 0;
for (Segment segment : segments) {
if (startOffset - offset < segment.getLength()
&& 0 < endOffset - offset) {
// part of the segment belongs on the sub-route
int subsegmentStartOffset =
segment.getStartOffset()
+ Math.max(startOffset - offset, 0);
int subsegmentLength =
(Math.min(endOffset - offset, segment.getLength()) -
Math.max(startOffset - offset, 0));
subsegments.add(new Segment(segment.getSection(), segment
.getDepartingEndPoint(), subsegmentStartOffset,
subsegmentStartOffset + subsegmentLength));
}
offset += segment.getLength();
}
return new Route(subsegments);
}
当我尝试在调用此方法的新类中创建另一个方法时,我收到错误:
我的代码如下,此错误出现在[Route newRoute = new Route()]
行public Route subRouteV(int startOffset, int endOffset){
Route newRoute = new Route();
Route vSubR = newRoute.getSubroute(startOffset, endOffset);
}
答案 0 :(得分:0)
问题来自那条线
Route newRoute = new Route();
你必须
Route
的构造函数
Route
构建一个不带参数的新构造函数。