After exporting the program, when I try to run the JAR file, the error occurs:
a JNI error occurred, check your installation and try again followed by a java exception occurred.
I have no idea how to solve this, I don't know if it's something about the code or the Java version
I'll post the code here (the main code) so please help!
My java is: 8 281 as JDK
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class Game extends Canvas implements Runnable, KeyListener{
/**
*
*/
private static final long serialVersionUID = 1L;
public static int WIDTH = 160;
public static int HEIGHT = 120;
public static int SCALE = 3;
public BufferedImage layer = new BufferedImage(WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB);
public static Enemy enemy;
public static Player player;
public static Ball ball;
public Game() {
this.setPreferredSize(new Dimension(WIDTH*SCALE,HEIGHT*SCALE));
this.addKeyListener(this);
player = new Player(60, HEIGHT-5);
enemy = new Enemy(60, 0);
ball = new Ball(60, HEIGHT/2 - 1);
}
public static void main(String[] args) {
Game game = new Game();
JFrame frame = new JFrame("Pong by Skubs");
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(game);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
new Thread(game).start();
}
public void tick() {
player.tick();
enemy.tick();
ball.tick();
}
public void render() {
BufferStrategy bs = this.getBufferStrategy();
if(bs == null) {
this.createBufferStrategy(3);
return;
}
Graphics g = layer.getGraphics();
g.setColor(Color.black);
g.fillRect(0, 0 , WIDTH, HEIGHT);
g.setColor(Color.white);
g.fillRect(0, 60 , WIDTH, HEIGHT/120);
player.render(g);
enemy.render(g);
ball.render(g);
g = bs.getDrawGraphics();
g.drawImage(layer, 0, 0, WIDTH*SCALE, HEIGHT*SCALE, null);
bs.show();
}
@Override
public void run() {
requestFocus();
while(true) {
tick();
render();
try {
Thread.sleep(1000/60);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_RIGHT) {
player.right = true;
}else if(e.getKeyCode() == KeyEvent.VK_LEFT) {
player.left = true;
}
}
@Override
public void keyReleased(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_RIGHT) {
player.right = false;
}else if(e.getKeyCode() == KeyEvent.VK_LEFT) {
player.left = false;
}
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
}
enter code here
question from:
https://stackoverflow.com/questions/65836303/a-jni-error-has-occurred-please-check-your-installation-and-try-again-and-a-jav 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…