Search code examples
javatimerintargs

How can I transform a Java String from args[] to an integer


I've got a little problem with the java Timer:

The main point is that it converts args[] to an int (which I can place in a timer-time)

My code looks just like this:

String bArgs = sArgument;
int minutes = Integer.parseInt(args[1].toString());
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
      @Override
      public void run() {
        Bukkit.broadcastMessage(ChatColor.GOLD + "[" + ChatColor.RED + "Werbung" + ChatColor.GOLD + "]" + ChatColor.BOLD + ChatColor.DARK_AQUA + bArgs);
      }
    }, 1*minutes*1000, 1*minutes*1000);
    return true;

But I can't convert the args[1] to an Int that I can place this int in the timer :(


Solution

  • args[0] is the first argument :

    public static void main(String[] args) {
            int minutes = Integer.parseInt(args[0]);
            Timer timer = new Timer();
            timer.scheduleAtFixedRate(new TimerTask() {
                  @Override
                  public void run() {
                      System.out.println("timer job...");             }
                }, 1*minutes*1000, 1*minutes*1000);
        }