Я столкнулся с проблемой Java. Моя программа выдала мне ошибку. UnsatisfiedLinkError, но файл - это они.JAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Я столкнулся с проблемой Java. Моя программа выдала мне ошибку. UnsatisfiedLinkError, но файл - это они.

Сообщение Anonymous »

У меня есть программа на Java, использующая собственный файл DLL. Он отлично работает на моей машине разработки, но выдает ошибку UnsatisfiedLinkError или «файл не найден» при запуске на другом устройстве.
Я уже установил все настройки для dll и intelliJ все равно выдавали эту ошибку, я также проверил dll и Java - 64-битную версию.
Файл находится в правильном месте.
Мои вопросы:
  • Каковы другие потенциальные причины, по которым DLL не может быть найдена, даже если она
    существует по указанному пути?
  • Есть ли какие-либо дополнительные конфигурации системы или Java, необходимые для загрузки собственных библиотек на новое устройство?
    Может ли это быть связано с зависимостями в самой DLL, и если да, то как я могу это отладить?
#Исключение в «основном» потоке java.lang.UnsatisfiedLinkError: невозможно загрузить библиотеку:
C:\Users\foru\CLionProjects\CheckerGameLibrary\cmake-build-debug\libCheckerGameLibrary.dll
в java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2422)
в java.base/java.lang.Runtime.load0(Runtime.java:852)
в java.base/ java.lang.System.load(System.java:2025)
в main.Main.(Main.java:156)
Процесс завершен с кодом завершения 1#

package main;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
//i send you complete file just unzip that and i set the setting in the code so set the run into Current file like that
public class Main {
private static final int BOARD_SIZE = 8;
private long gamePtr; // Pointer to the C++ game instance
private int[][] boardState; // 2D array to hold board state
private JButton[][] buttons; // To keep track of buttons for painting
private JLabel turnLabel; // Label to show which player's turn it is
private int selectedRow = -1; // No piece selected initially
private int selectedCol = -1; // No piece selected initially

public Main() {
// Initialize the game and fetch the initial board state
gamePtr = nativeCreate();
boardState = fetchBoardState();

// Set up GUI
JFrame frame = new JFrame("Checker Game");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 600); // Increased size for better visual
frame.setLayout(new BorderLayout()); // Use BorderLayout for the frame

// Create the turn label
turnLabel = new JLabel("Current Turn: Player " + getCurrentPlayer(gamePtr));
turnLabel.setHorizontalAlignment(SwingConstants.CENTER);
frame.add(turnLabel, BorderLayout.NORTH); // Add label at the top

JPanel boardPanel = new JPanel(new GridLayout(BOARD_SIZE, BOARD_SIZE));
buttons = new JButton[BOARD_SIZE][BOARD_SIZE];

initializeBoard(boardPanel);
frame.add(boardPanel, BorderLayout.CENTER); // Add board panel to the center

frame.setVisible(true);
}

public void initializeBoard(JPanel boardPanel) {
for (int row = 0; row < BOARD_SIZE; row++) {
for (int col = 0; col < BOARD_SIZE; col++) {
final int finalRow = row; // Declare final variable for row
final int finalCol = col; // Declare final variable for col

JButton button = new JButton() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
drawPiece(g, finalRow, finalCol); // Use finalRow and finalCol
}
};

// Set button background color based on the position
if ((row + col) % 2 == 0) {
button.setBackground(new Color(255, 206, 158)); // Light color
} else {
button.setBackground(new Color(186, 120, 49)); // Dark color
}
button.setOpaque(true);
button.setBorderPainted(false); // Remove button border
buttons[row][col] = button; // Store button reference

button.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (selectedRow == -1) { // No piece selected
if (boardState[finalRow][finalCol] == getCurrentPlayer(gamePtr)) {
selectedRow = finalRow;
selectedCol = finalCol;
button.setBackground(Color.YELLOW); // Highlight selected piece
}
} else { // Piece has been selected
if (movePiece(gamePtr, selectedRow, selectedCol, finalRow, finalCol)) {
boardState = fetchBoardState(); // Refresh board state after move
updateTurnLabel(); // Update turn label after a successful move
checkGameOver(); // Check if game is over
}
resetSelection(); // Clear selection regardless of move success
}
updateBoard(); // Update the visual board
}
});

boardPanel.add(button); // Add button to the board panel
}
}
}

public void drawPiece(Graphics g, int row, int col) {
if (boardState != null && boardState[row][col] != 0) {
int pieceColor = boardState[row][col];
g.setColor(pieceColor == 1 ? Color.BLACK : Color.WHITE);
g.fillOval(10, 10, 50, 50); // Adjusted size of pieces
}
}

public int[][] fetchBoardState() {
int[] array = getBoardState(gamePtr); // Replace jintArray with int[]
int[][] state = new int[BOARD_SIZE][BOARD_SIZE];

for (int row = 0; row < BOARD_SIZE; row++) {
for (int col = 0; col < BOARD_SIZE; col++) {
state[row][col] = array[row * BOARD_SIZE + col]; // Adjust for 1D indexing
}
}
return state;
}

public void updateBoard() {
for (int row = 0; row < BOARD_SIZE; row++) {
for (int col = 0; col < BOARD_SIZE; col++) {
buttons[row][col].repaint(); // Repaint each button
}
}
}

public void updateTurnLabel() {
int currentPlayer = getCurrentPlayer(gamePtr); // Get the current player
turnLabel.setText("Current Turn: Player " + currentPlayer); // Update label text
}

public void checkGameOver() {
int winner = checkWinner(gamePtr);
if (winner != 0) {
JOptionPane.showMessageDialog(null, "Player " + winner + " wins!");
int response = JOptionPane.showConfirmDialog(null, "Play again?", "Game Over", JOptionPane.YES_NO_OPTION);
if (response == JOptionPane.YES_OPTION) {
resetGame();
} else {
System.exit(0);
}
}
}

public void resetGame() {
resetGameNative(gamePtr); // Reset the game on the native side
boardState = fetchBoardState(); // Refresh the board state
updateBoard(); // Repaint the board
updateTurnLabel(); // Update the turn label for a fresh start
}

public void resetSelection() {
if (selectedRow != -1 && selectedCol != -1) {
buttons[selectedRow][selectedCol].setBackground((selectedRow + selectedCol) % 2 == 0 ? new Color(255, 206, 158) : new Color(186, 120, 49));
}
selectedRow = -1;
selectedCol = -1;
}

static {
//here in main function paste that
// System.out.println("Loading library from: " + System.getProperty("java.library.path"));// donot change that because we both have same name just change
System.load("C:/Users/foru/CLionProjects/CheckerGameLibrary/cmake-build-debug/libCheckerGameLibrary.dll");
// Correct way to load
}
public native long nativeCreate();
public native int[] getBoardState(long ptr); // Change jintArray to int[]
public native boolean movePiece(long ptr, int fromRow, int fromCol, int toRow, int toCol); // Native method to move pieces
public native int getCurrentPlayer(long ptr); // Get the current player's ID
public native int checkWinner(long ptr); // Native method to check for winner
public native void resetGameNative(long ptr); // Native method to reset the game

public static void main(String[] args) {
SwingUtilities.invokeLater(Main::new);
}
}


Подробнее здесь: https://stackoverflow.com/questions/791 ... -but-the-f
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»