java 我试图加载的球员和球员的位置到数据库时,打破块,但它输出一个错误

pcww981p  于 2023-11-15  发布在  Java
关注(0)|答案(1)|浏览(87)

EventBlock

package minecord.plugingenerin.Event;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;

import javax.management.timer.Timer;
import java.util.concurrent.ExecutorService;

public class EventBlock implements Listener {

    @EventHandler
    public void onDestroy(BlockBreakEvent blockBreak) throws SQLException {
        Player player = blockBreak.getPlayer(); //Получение игрока
        Block block = blockBreak.getBlock();
        Location loc = block.getLocation();
        World world = block.getWorld();
        Material material = block.getType();
        player.sendMessage("Блок сломан");
        SqliteDB db =new SqliteDB();
        db.insert(loc,player);

    }
}

字符串
SqliteDB

package minecord.plugingenerin.Event;

import org.bukkit.Location;
import org.bukkit.entity.Player;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class SqliteDB {
    SqliteDB program = new SqliteDB();
    Connection c = DriverManager.getConnection("jdbc:sqlite:memory:F:/Location.db");
    Statement stmt = c.createStatement();
    void insert(Location location, Player user) throws SQLException {
        stmt.executeUpdate("insert LocatioInfo values('"+location+"','"+user+"')");
        stmt.executeUpdate("backup to C:Users/Татьяна/Desktop/Server 1.20.1 paper/plugins/DB/backup.db");
    }

    public SqliteDB() throws SQLException {
        stmt.executeUpdate("create table Location(Location Location, User TEXT)");

    }
}


误差
[16:56:39 ERROR]:无法将事件BlockBreakEvent传递到PluginGenerin v1.0 java.lang。StackOverflowError:null at minecord. plugingenerin. Event. SqliteDB。(SqliteDB.java:12)~[original-PluginGenerin-1.0.jar:?] at minecord. plugingenerin. Event. SqliteDB.(SqliteDB.java:12)~[original-PluginGenerin-1.0.jar:?] at minecord. plugingenerin. Event. SqliteDB.(SqliteDB.java:12)~[original-PluginGenerin-1.0.jar:?] at minecord. plugingenerin. Event. SqliteDB.(SqliteDB.java:12)~[original-PluginGenerin-1.0.jar:?] at minecord. plugingenerin. Event. SqliteDB.(SqliteDB.java:12)~[original-PluginGenerin-1.0.jar:?] at minecord. plugingenerin. Event. SqliteDB.(SqliteDB.java:12)~[original-PluginGenerin-1.0.jar:?]
我尝试删除SqliteDB db =new SqliteDB(); db.insert(loc,player);

enyaitl3

enyaitl31#

你的问题是由这句话引起的:

public class SqliteDB {
    SqliteDB program = new SqliteDB();
    ...
}

字符串
当类SqliteDB被示例化时,字段program被创建并分配给一个新的SqliteDB类,该类具有一个字段program,该字段被创建并分配给一个新的SqliteDB类,依此类推,直到发生堆栈溢出。

相关问题