Hey I have small problem but I can’t fix it 🙁 I use mysql + bukkit libraries, and when I want use one of the methods I get error of unreachable code
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 and here i connect to sql but i have problem with unreachable code
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();
}
}
what is wrong ?
You really need to point out where are you getting the unreachable code message. With the current information all we can do is guesswork.
Still, some examples of common dead code cases are
or
In this case, you have an
ifand itselseboth returning a value, hence the code after those statements won’t be executed.You need to work on what do you want to do there.