无法解析构造函数 'Stage(com.badlogic.gdx.utils.viewport.Viewport, com.badlogic.gdx.graphics.g2d.SpriteBatch)'

Cannot resolve constructor 'Stage(com.badlogic.gdx.utils.viewport.Viewport, com.badlogic.gdx.graphics.g2d.SpriteBatch)'

我是 libgdx 的初学者。尝试制作游戏时,我在 Android Studio 中遇到此错误:

Error:(39, 16) Gradle: error: no suitable constructor found for Stage(Viewport,SpriteBatch) constructor Stage.Stage() is not applicable (actual and formal argument lists differ in length) constructor Stage.Stage(StageStyle) is not applicable (actual and formal argument lists differ in length)

-

public class Hud {
|  public Stage stage;
|  private Viewport viewport;
|  
|  private Integer worldTimer;
|  private float timeCount;
|  private Integer score;
|  
|  Label countdownLabel;
|  Label scoreLabel;
|  Label timeLabel;
|  Label levelLabel;
|  Label worldLabel;
|  Label snakeLabel;
|  
|  public Hud(SpriteBatch sb) {
|  |  worldTimer = 300;
|  |  timeCount = 0;
|  |  score = 0;
|  |  
|  |  viewport = new FitViewport(Snake.V_WIDTH, Snake.V_HEIGHT, new OrthographicCamera());
|  |  stage = new Stage(viewport,sb);    
|  }
}

这是错误:

stage = new Stage(viewport,sb);

我在互联网上搜索了一些解决方案,但我没有找到任何东西。我有点迷路了。 请原谅我的英语不好:) 我希望你能帮助我 。我将不胜感激。

你导入了错误的 Stage class,应该是:

com.badlogic.gdx.scenes.scene2d.Stage

但您可能有这个或其他一些软件包:

javafx.stage.Stage