有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何修复可选文件的StackOverflow错误?

我正在为班级做作业,但我似乎不知道是什么导致了这个StackOverflow错误

一些背景:

此特定方法的要点是使用MoveStrategy接口返回沿直线移动的可选值。参数dxdy充当我们的“偏移”,我们必须将它们添加到BlobView的当前位置

public class StraightLineMovement implements MoveStrategy
{

  private final int dx;
  private final int dy;

  /**
   * Construct an instance which will, on each call to move, move the blob by the given offsets.
   *
   * @param dx the distance the Blob should move along the x axis
   * @param dy the distance the Blob should move along the y axis
   */
  public StraightLineMovement(int dx, int dy) 
  {
      this.dx = dx;
      this.dy = dy;
  }

  @Override
  public Optional<Point> move(BlobView bv) 
  {
        Point bvLocation = bv.getLocation();
        double bvRadius = bv.getRadius();
        
        int bv_X = bvLocation.x + dx;
        int bv_Y = bvLocation.y + dy;
        
        Point newLocation = new SimplePoint (bv_X, bv_Y);
        
        StraightLineMovement strategy = new StraightLineMovement (dx, dy);
        
        
        BlobView newView = new BlobView (newLocation, bvRadius);
        System.out.println ("Point: (" + newLocation.x + ", " + newLocation.y + ")");
        
        Optional <Point> movement = strategy.move(newView);
       
        return movement;
        //return movement.map(point -> point.moveTo(new_X, new_Y));
  }
}

当我实际使成为可选项时,它一直给我这个错误

以下是MoveStrategy界面:

import java.util.Optional;

public interface MoveStrategy 
{

    public Optional<Point> move(BlobView bv);
}

我想指出的是,我从print语句得到的结果是正确的(如中所示,它们正在正确移动),但我就是不知道如何解决这个问题。起初,我以为这是我的返回语句(现在仍然可以),但我尝试使用它。地图过滤器等。我想试着把它修好,但我想不出来

任何帮助都将不胜感激,谢谢


共 (0) 个答案