嘿我有小问题,但我无法解决它:(我使用mysql + bukkit库,当我想使用其中一种方法时,我得到无法访问代码的错误
Main.java
package Hester.CrafMe;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
protected static final Logger log=Logger.getLogger("Minecraft");
private static final String ALPHA_NUM = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public Colorizer colorize = new Colorizer();
public MySQL sql = new MySQL();
public static Main plugin;
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
final FileConfiguration config = this.getConfig();
Player player = (Player) sender;
int LANG = config.getInt("PlayerConfig."+player.getName()+".language");
//uKEY(unikalny kod)
if (command.getName().equalsIgnoreCase("ukey")){
String Private_uKEY = uKEY(7);
if(LANG == 1){
player.sendMessage(ChatColor.RED + "Twoj unikalny kod to: "+ ChatColor.YELLOW + Private_uKEY);
player.sendMessage(ChatColor.RED + "Podany kod wpisz na stronie "+ ChatColor.YELLOW + "www.crafme.net");
return true;
} else {
player.sendMessage(ChatColor.RED + "Your unique code is: "+ ChatColor.YELLOW + Private_uKEY);
player.sendMessage(ChatColor.RED + "Enter the code on the page "+ ChatColor.YELLOW + "www.crafme.net");
return true;
}
sql.uKEY(Private_uKEY, player.getName());
}
return false;
}
}
MySQL.java ,这里我连接到sql但是我遇到了无法访问代码的问题
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import org.bukkit.event.Listener;
public class MySQL implements Listener {
private Connection connect = null;
private Statement statement = null;
private PreparedStatement preparedStatement = null;
private ResultSet resultSet = null;
public void connect() throws Exception {
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost....?"+ "user=test&password=whatever");
statement = connect.createStatement();
... more code
} catch (Exception e) {
throw e;
} finally {
close();
}
}
出了什么问题?
答案 0 :(得分:1)
您真的需要指出在哪里获得无法访问的代码消息。根据当前的信息,我们所能做的只是猜测。
但是,常见死代码案例的一些例子是
public String getProperty() {
return "property";
System.out.println("Dead code"); //Code after a return statement
}
或
//Method...
throw new Exception();
//Unreachable code from now on, after an exception is thrown.
在这种情况下,您有一个if
且其else
都返回一个值,因此这些语句之后的代码将无法执行。
if (command.getName().equalsIgnoreCase("ukey")){
String Private_uKEY = uKEY(7);
if(LANG == 1){
player.sendMessage(ChatColor.RED + "Twoj unikalny kod to: "+ ChatColor.YELLOW + Private_uKEY);
player.sendMessage(ChatColor.RED + "Podany kod wpisz na stronie "+ ChatColor.YELLOW + "www.crafme.net");
return true; //Returning a value
} else {
player.sendMessage(ChatColor.RED + "Your unique code is: "+ ChatColor.YELLOW + Private_uKEY);
player.sendMessage(ChatColor.RED + "Enter the code on the page "+ ChatColor.YELLOW + "www.crafme.net");
return true; //Returning a value on the else too
}
//Since both the if and the else return something, the code below won't be executed.
sql.uKEY(Private_uKEY, player.getName());
}
return false;
你需要研究你想做什么。