if语句中没有调用其他类的方法。在其他地方打电话很好

时间:2016-07-08 13:36:57

标签: java command-line-interface

好的,当我在if语句中调用CommandMethods(另一个类)的方法时程序终止。但是当我在其他任何地方打电话时,它都有效!我不明白为什么会这样做而且我真的想知道。

代码:

getCommand();

CommandMethods cm = new CommandMethods();

    if(Arrays.asList(commands[0]).equals(nextCommand)){
        cm.deauth();

    }else if(Arrays.asList(commands[1]).equals(nextCommand)){

        cm.exploit();


    }else if (Arrays.asList(commands[2]).equals(nextCommand)){

        cm.set();
    }

有人可以帮助我吗?

-Thanks

编辑:

完整代码:

package ca.wax.main;
import java.util.Arrays;
import java.util.Scanner;
public class Wax {

static String commands[];
    static Scanner s = new Scanner(System.in);
    static boolean containsCommand;
    static String nextCommand;
public static String getCommand(){ 

    do {
        nextCommand = s.nextLine();
        containsCommand = false;

        for (int i = 0; i < commands.length; i++) {
            if (commands[i].equals(nextCommand)) {
                containsCommand = true;
                return nextCommand;
            }    
        } 
        if (!containsCommand) {
            System.out.println("Cannot find command");
        }
        }while(!containsCommand);
    return null;
    }


public static void main(String[]args){

    CommandMethods cm = new CommandMethods();
    commands = new String[3];
    commands[0] = "deauth";
    commands[1] = "exploit";
    commands[2] = "set";



    System.out.println("Welcome to Wax!");
    System.out.println();
    System.out.println();
    System.out.println();
    System.out.println("Wax >");

    getCommand();
    if(Arrays.asList(commands[0]).equals(nextCommand)){
        cm.deauth();

    }else if(Arrays.asList(commands[1]).equals(nextCommand)){




    }else if (Arrays.asList(commands[2]).equals(nextCommand)){


    }







}

}

0 个答案:

没有答案