好吧,首先也是最重要的一点,我是Java新手,但不是编程新手。
对于一个个人项目,我决定使用Slick2D,Java中的一个图形库,我遇到了一个暂时无法解决的问题。
考虑到以下因素:
我使用netbeans
我现在在Linux上
据我所知,slick2d使用lwgjl。我已按照下页的说明操作:
Setting up Slick2D for netbeans
我的问题是给jvm提供正确的选项。
目前我设置的是:
-java.library.path=/home/karel/téléchargements/slick/native/unix
这是我得到的当前错误输出:
run:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl64 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.lwjgl.Sys$1.run(Sys.java:72)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:87)
at org.lwjgl.Sys.<clinit>(Sys.java:117)
at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
at org.newdawn.slick.AppGameContainer$1.run(AppGameContainer.java:39)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.AppGameContainer.<clinit>(AppGameContainer.java:36)
at jcoinche.client.JcoincheClient.main(JcoincheClient.java:29)
/home/karel/.cache/netbeans/8.1/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
我的代码如下(好吧,那部分需要一个库,但不起作用-顺便说一下,这都是教程材料。我什么都没做):
package jcoinche.client;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Scanner;
import static jcoinche.client.Game.gamename;
import static jcoinche.client.Game.xSize;
import static jcoinche.client.Game.ySize;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.SlickException;
public class JcoincheClient
{
public static void main(String[] args)
{
Socket socket;
AppGameContainer appgc;
try
{
appgc = new AppGameContainer(new Game(gamename));
appgc.setDisplayMode(xSize, ySize, false);
appgc.setTargetFrameRate(60);
appgc.start();
}
catch(SlickException e)
{
e.printStackTrace();
}
}
游戏.java:
package jcoinche.client;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Game extends StateBasedGame
{
public static final String gamename = "MyGameName";
public static final int play = 0;
public static final int xSize = 400;
public static final int ySize = 300;
public Game(String gamename){
super(gamename);
this.addState(new Play());
}
public void initStatesList(GameContainer gc) throws SlickException{
this.getState(play).init(gc, this);
this.enterState(play);
}
}
播放.java:
package jcoinche.client;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
public class Play extends BasicGameState
{
public Play()
{
}
public void init(GameContainer gc, StateBasedGame sbg)
throws SlickException
{
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g)
throws SlickException
{
}
public void update(GameContainer gc, StateBasedGame sbg, int delta)
throws SlickException
{
}
public int getID()
{
return 0;
}
}
最佳答案
错误是告诉您缺少名为“lwjgl64”的文件。您将得到一个不满意的linkerror,根据java文档,它是:
Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.
现在,你一个人在用slick2d吗?或者你有LWJGL和SLICK2D吗?slick2d不是独立的;您需要lwjgl来运行它。我建议从their site,获取lwjgl,并将它的本机文件夹添加到类路径中。
从Slick2D文档中,他们写道:
-Djava.library.path=<lwjgl-X.X path>/native/<linux|macosx|solaris|windows>
Source