此代码是使角色行走。我添加了所有库和lwjgl文件。这是控制台中打印的内容:


错误:找不到或加载主类
org.newdawn.slick.tests.AlphaMapTest原因由:
java.lang.ClassNotFoundException:org.newdawn.slick.tests.AlphaMapTest


主要课程:

    import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

public class Principal extends StateBasedGame{
    private AppGameContainer contenitore;//contenitore
    public Principal() throws SlickException {
        super("Prova");
        contenitore=new AppGameContainer(this);
        contenitore.setDisplayMode(1280,720,false);
        contenitore.setShowFPS(false);//non faccio vedere gli fps
        contenitore.start();//fa partire initStateList
        // TODO Auto-generated constructor stub
    }

    /*
     * Inizializza la lista degli stati del gioco che con BasedGame non si poteva fare
     */
    public void initStatesList(GameContainer arg0) throws SlickException {
        // TODO Auto-generated method stub

        this.addState(new Gioco());//aggiungo uno stato che � il nuovo gioco
    }
    public static void main(String[] args)
    {
        try
        {
            new Principal();

        }
        catch(SlickException exc)
        {
            exc.printStackTrace();//stampo l'eccezione

        }
    }


}


游戏类别:

    import org.newdawn.slick.Animation;
    import org.newdawn.slick.GameContainer;
    import org.newdawn.slick.Graphics;
    import org.newdawn.slick.Image;
    import org.newdawn.slick.Input;
    import org.newdawn.slick.SlickException;
    import org.newdawn

.slick.SpriteSheet;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.w3c.dom.css.Rect;

public class Gioco extends BasicGameState {


    Input entrata;
    Image sfondo;
    boolean toccato=false;
    float hx=100,hy=100,cx=400,cy=100;
    float x=300,y=300;
    Animation omov;
    SpriteSheet o;

    int posizione=0;

    public void init(GameContainer contenitore, StateBasedGame arg1) throws SlickException {

        // TODO Auto-generated method stub
        entrata=contenitore.getInput();
        sfondo=new Image("/img/s.png");
        o=new SpriteSheet("/img/movimento.png",32,32);
        //allora si prende la dimensione dell'immagine e si sceglie
        //l'area che si vuole ripetere movimento png � una 292x256
        //ed � una matrice 8x9 quindi ho diviso 292/9 32,4(larghezza) e 256/8=32(altezza)
        omov=new Animation(o,50);//100 indica ogni quanti ms far scattare il fotogramma
        omov.setAutoUpdate(true);//animazione automatica fissarla a falsa e usa il metood update per aggiornare di default � true
        omov.setLooping(true);//se non voglio mandare in loop animazione di default � true

    }
    public void render(GameContainer arg0, StateBasedGame arg1, Graphics g) throws SlickException {
        // TODO Auto-generated method stub
        sfondo.draw(0,0,1280,720);
        omov.getImage(posizione).draw(x,y,60,60);

    }

    @Override
    public void update(GameContainer arg0, StateBasedGame arg1, int arg2) throws SlickException {
        // TODO Auto-generated method stub


    }
    public void movimentoOmino()
    {
         if(entrata.isKeyDown(Input.KEY_DOWN))//se sto premendo il tasto giu
         {
             if(posizione>3)
                 posizione=-1;
             y++;

             posizione++;
             if (posizione==3)
                 posizione=0;
         }
         if(entrata.isKeyDown(Input.KEY_UP))//se sto premendo il tasto giu
         {
             if(posizione<27||posizione>29)
                 posizione=26;
             y--;

             posizione++;
             if (posizione==30)
                 posizione=27;
         }
         if(entrata.isKeyDown(Input.KEY_LEFT))//se sto premendo il tasto giu
         {
             if(posizione>11||posizione<9)
                 posizione=8;
             x--;

             posizione++;
             if (posizione==12)
                 posizione=9;
         }
         if(entrata.isKeyDown(Input.KEY_RIGHT))//se sto premendo il tasto giu
         {
             if(posizione<18||posizione>20)
                 posizione=17;
             x++;

             posizione++;
             if (posizione==21)
                 posizione=18;
         }
         if(x<0)
         {
             x=0;

         }
         if(x+omov.getWidth()>1000)
         {
             x=1000-omov.getWidth();

         }
         if(y<0)
         {
             y=0;

         }
         if(y+omov.getHeight()>720)
         {
             y=720-omov.getHeight();

         }
    }



    @Override
    public int getID() {
        // TODO Auto-generated method stub
        return 0;
    }

}


滑动库中的ALPHAMAPTEST类:

  // Compiled from AlphaMapTest.java (version 1.5 : 49.0, super bit)
public class org.newdawn.slick.tests.AlphaMapTest extends org.newdawn.slick.BasicGame {

  // Field descriptor #38 Lorg/newdawn/slick/Image;
  private org.newdawn.slick.Image alphaMap;

  // Field descriptor #38 Lorg/newdawn/slick/Image;
  private org.newdawn.slick.Image textureMap;

  // Method descriptor #41 ()V
  // Stack: 2, Locals: 1
  public AlphaMapTest();
    0  aload_0 [this]
    1  ldc <String "AlphaMap Test"> [1]
    3  invokespecial org.newdawn.slick.BasicGame(java.lang.String) [2]
    6  return
      Line numbers:
        [pc: 0, line: 26]
        [pc: 6, line: 27]
      Local variable table:
        [pc: 0, pc: 7] local: this index: 0 type: org.newdawn.slick.tests.AlphaMapTest

  // Method descriptor #48 (Lorg/newdawn/slick/GameContainer;)V
  // Stack: 4, Locals: 2
  public void init(org.newdawn.slick.GameContainer container) throws org.newdawn.slick.SlickException;
     0  aload_0 [this]
     1  new org.newdawn.slick.Image [3]
     4  dup
     5  ldc <String "testdata/alphamap.png"> [4]
     7  invokespecial org.newdawn.slick.Image(java.lang.String) [5]
    10  putfield org.newdawn.slick.tests.AlphaMapTest.alphaMap : org.newdawn.slick.Image [6]
    13  aload_0 [this]
    14  new org.newdawn.slick.Image [3]
    17  dup
    18  ldc <String "testdata/grass.png"> [7]
    20  invokespecial org.newdawn.slick.Image(java.lang.String) [5]
    23  putfield org.newdawn.slick.tests.AlphaMapTest.textureMap : org.newdawn.slick.Image [8]
    26  aload_1 [container]
    27  invokevirtual org.newdawn.slick.GameContainer.getGraphics() : org.newdawn.slick.Graphics [9]
    30  getstatic org.newdawn.slick.Color.black : org.newdawn.slick.Color [10]
    33  invokevirtual org.newdawn.slick.Graphics.setBackground(org.newdawn.slick.Color) : void [11]
    36  return
      Line numbers:
        [pc: 0, line: 33]
        [pc: 13, line: 34]
        [pc: 26, line: 35]
        [pc: 36, line: 36]
      Local variable table:
        [pc: 0, pc: 37] local: this index: 0 type: org.newdawn.slick.tests.AlphaMapTest
        [pc: 0, pc: 37] local: container index: 1 type: org.newdawn.slick.GameContainer

  // Method descriptor #53 (Lorg/newdawn/slick/GameContainer;I)V
  // Stack: 0, Locals: 3
  public void update(org.newdawn.slick.GameContainer container, int delta) throws org.newdawn.slick.SlickException;
    0  return
      Line numbers:
        [pc: 0, line: 43]
      Local variable table:
        [pc: 0, pc: 1] local: this index: 0 type: org.newdawn.slick.tests.AlphaMapTest
        [pc: 0, pc: 1] local: container index: 1 type: org.newdawn.slick.GameContainer
        [pc: 0, pc: 1] local: delta index: 2 type: int

  // Method descriptor #57 (Lorg/newdawn/slick/GameContainer;Lorg/newdawn/slick/Graphics;)V
  // Stack: 5, Locals: 3
  public void render(org.newdawn.slick.GameContainer container, org.newdawn.slick.Graphics g) throws org.newdawn.slick.SlickException;
     0  aload_2 [g]
     1  invokevirtual org.newdawn.slick.Graphics.clearAlphaMap() : void [12]
     4  aload_2 [g]
     5  getstatic org.newdawn.slick.Graphics.MODE_NORMAL : int [13]
     8  invokevirtual org.newdawn.slick.Graphics.setDrawMode(int) : void [14]
    11  aload_0 [this]
    12  getfield org.newdawn.slick.tests.AlphaMapTest.textureMap : org.newdawn.slick.Image [8]
    15  ldc <Float 10.0> [15]
    17  ldc <Float 50.0> [16]
    19  invokevirtual org.newdawn.slick.Image.draw(float, float) : void [17]
    22  aload_2 [g]
    23  getstatic org.newdawn.slick.Color.red : org.newdawn.slick.Color [18]
    26  invokevirtual org.newdawn.slick.Graphics.setColor(org.newdawn.slick.Color) : void [19]
    29  aload_2 [g]
    30  ldc <Float 290.0> [20]
    32  ldc <Float 40.0> [21]
    34  ldc <Float 200.0> [22]
    36  ldc <Float 200.0> [22]
    38  invokevirtual org.newdawn.slick.Graphics.fillRect(float, float, float, float) : void [23]
    41  aload_2 [g]
    42  getstatic org.newdawn.slick.Color.white : org.newdawn.slick.Color [24]
    45  invokevirtual org.newdawn.slick.Graphics.setColor(org.newdawn.slick.Color) : void [19]
    48  aload_2 [g]
    49  getstatic org.newdawn.slick.Graphics.MODE_ALPHA_MAP : int [25]
    52  invokevirtual org.newdawn.slick.Graphics.setDrawMode(int) : void [14]
    55  aload_0 [this]
    56  getfield org.newdawn.slick.tests.AlphaMapTest.alphaMap : org.newdawn.slick.Image [6]
    59  ldc <Float 300.0> [26]
    61  ldc <Float 50.0> [16]
    63  invokevirtual org.newdawn.slick.Image.draw(float, float) : void [17]
    66  aload_2 [g]
    67  getstatic org.newdawn.slick.Graphics.MODE_ALPHA_BLEND : int [27]
    70  invokevirtual org.newdawn.slick.Graphics.setDrawMode(int) : void [14]
    73  aload_0 [this]
    74  getfield org.newdawn.slick.tests.AlphaMapTest.textureMap : org.newdawn.slick.Image [8]
    77  ldc <Float 300.0> [26]
    79  ldc <Float 50.0> [16]
    81  invokevirtual org.newdawn.slick.Image.draw(float, float) : void [17]
    84  aload_2 [g]
    85  getstatic org.newdawn.slick.Graphics.MODE_NORMAL : int [13]
    88  invokevirtual org.newdawn.slick.Graphics.setDrawMode(int) : void [14]
    91  return
      Line numbers:
        [pc: 0, line: 50]
        [pc: 4, line: 51]
        [pc: 11, line: 52]
        [pc: 22, line: 53]
        [pc: 29, line: 54]
        [pc: 41, line: 55]
        [pc: 48, line: 57]
        [pc: 55, line: 58]
        [pc: 66, line: 59]
        [pc: 73, line: 60]
        [pc: 84, line: 61]
        [pc: 91, line: 62]
      Local variable table:
        [pc: 0, pc: 92] local: this index: 0 type: org.newdawn.slick.tests.AlphaMapTest
        [pc: 0, pc: 92] local: container index: 1 type: org.newdawn.slick.GameContainer
        [pc: 0, pc: 92] local: g index: 2 type: org.newdawn.slick.Graphics

  // Method descriptor #61 (IC)V
  // Stack: 0, Locals: 3
  public void keyPressed(int key, char c);
    0  return
      Line numbers:
        [pc: 0, line: 68]
      Local variable table:
        [pc: 0, pc: 1] local: this index: 0 type: org.newdawn.slick.tests.AlphaMapTest
        [pc: 0, pc: 1] local: key index: 1 type: int
        [pc: 0, pc: 1] local: c index: 2 type: char

  // Method descriptor #66 ([Ljava/lang/String;)V
  // Stack: 4, Locals: 2
  public static void main(java.lang.String[] argv);
     0  new org.newdawn.slick.AppGameContainer [28]
     3  dup
     4  new org.newdawn.slick.tests.AlphaMapTest [29]
     7  dup
     8  invokespecial org.newdawn.slick.tests.AlphaMapTest() [30]
    11  invokespecial org.newdawn.slick.AppGameContainer(org.newdawn.slick.Game) [31]
    14  astore_1 [container]
    15  aload_1 [container]
    16  sipush 800
    19  sipush 600
    22  iconst_0
    23  invokevirtual org.newdawn.slick.AppGameContainer.setDisplayMode(int, int, boolean) : void [32]
    26  aload_1 [container]
    27  invokevirtual org.newdawn.slick.AppGameContainer.start() : void [33]
    30  goto 38
    33  astore_1 [e]
    34  aload_1 [e]
    35  invokevirtual org.newdawn.slick.SlickException.printStackTrace() : void [35]
    38  return
      Exception Table:
        [pc: 0, pc: 30] -> 33 when : org.newdawn.slick.SlickException
      Line numbers:
        [pc: 0, line: 77]
        [pc: 15, line: 78]
        [pc: 26, line: 79]
        [pc: 30, line: 82]
        [pc: 33, line: 80]
        [pc: 34, line: 81]
        [pc: 38, line: 83]
      Local variable table:
        [pc: 15, pc: 30] local: container index: 1 type: org.newdawn.slick.AppGameContainer
        [pc: 34, pc: 38] local: e index: 1 type: org.newdawn.slick.SlickException
        [pc: 0, pc: 39] local: argv index: 0 type: java.lang.String[]
}

最佳答案

我有同样的问题,我通过将tile更改为1.3.2版来解决了

关于java - 错误:找不到或加载主类org.newdawn.slick.tests.AlphaMapTest,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60008651/

10-12 04:35