有 Java 编程相关的问题?

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

java动画是无法实例化的抽象

我在使用libGDX开发Android Studio时遇到这个错误

这是我的密码:

package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.Animation;

public class MyGdxGame extends ApplicationAdapter {
private SpriteBatch batch;
private TextureAtlas shooterAtlas;
private Animation animation;
private float timePassed = 0 ;

@Override
public void create () {
    batch = new SpriteBatch();
  shooterAtlas = new TextureAtlas(Gdx.files.internal("shooter.atlas"));
    animation = new Animation(1/30f,shooterAtlas.getRegions());
}

@Override
public void dispose() {
    batch.dispose();

 }

 @Override
 public void render () {
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    timePassed += Gdx.graphics.getDeltaTime();
    batch.draw(animation.getKeyFrame(timePassed,true),300,500);
    batch.end();

   }
 }

首先,我有这个代码:

import javafx.animation.animation

而不是:

import com.badlogic.gdx.graphics.g2d.Animation;

但这给了我一个错误:

animation = new Animation(1/30f,shooterAtlas.getRegions());

即: 动画是抽象的,不能实例化 但接下来我要导入以下内容:

import com.badlogic.gdx.graphics.g2d.Animation;

并删除:

import javafx.animation.animation

因为它给了我一个错误,你不能两者兼得,并且用alt+enter进行解析也不起作用

但在编译时,它给出了错误:

Warning:[options] bootstrap class path not set in conjunction with -source 1.6

C:\Users\COMPUTER\Documents\new libgdx\core\src\com\mygdx\game\MyGdxGame。JAVA 1警告 错误:任务“:core:compileJava”的执行失败

Compilation failed; see the compiler error output for details. Information:BUILD FAILED Information:Total time: 1.526 secs Information:2 errors Information:1 warning Information:See complete output in console


共 (1) 个答案

  1. # 1 楼答案

    最后一个错误是因为您正在使用以前的jdk版本编译代码,而您有一个更新的版本,请尝试将源代码和目标代码都设置为当前的jdk版本