-1

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 ?

4

1 回答 1

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;

你需要做你想在那里做的事情。

于 2012-11-09T20:02:54.857 回答