扫描仪课程有问题

时间:2013-10-27 12:04:01

标签: java

我正在JAVA中为我的计算机应用程序内部评估准备一个项目,尽管该类没有发现语法错误,但我在调用该方法时出错。 这是我的代码:

    package CommandPromptBrowser.GoogleWebsite;
    import java.util.*;
    class Commandprompt
    {
    Scanner sc=new Scanner(System.in);
    Searchbox se=new Searchbox();
    Title ti=new Title();
    Searchresults sr=new Searchresults();
    String cmd;
    String key;
    void commandBox()
    {
        System.out.println("***");
        cmd=sc.next();
        key=sc.next();
    }  
    boolean typeCommand()
    {
        if(cmd.equals("type>box"))
        {
            return(true);
        }
        else 
        {
            return(false);
        }
    }
    boolean clickCommand()
    {
        if(cmd.equals("click>button"))
        {
            if(key.equals(se.search))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            return(false);
        }
    }
    void commands()
    {
        boolean res;
        if(res=typeCommand())
        {
            se.searchBox(key);
            commandBox();
        }
        else if(res=clickCommand())
        {
            sr.resultScreen();
            commandBox();
        }
    }
}

如果我调用一个名为Googleclient的方法,我会收到以下错误:

java.lang.StackOverflowError:
null(in java.lang.String)

我认为麻烦是由于Scanner类对象造成的。 我想提一下Googleclient类的代码 -

    package CommandPromptBrowser.GoogleWebsite;
public class Googleclient
{
    Title ti=new Title();
    Searchbox sea=new Searchbox();
    Commandprompt cp=new Commandprompt();
    public void clientRunner()
    {
        ti.welcomeScreenTitle();
        sea.emptySearchBox();
        cp.commandBox();
        cp.clickCommand();
        cp.typeCommand();
        cp.commands();
    }
}

请尽快回复。请.....

1 个答案:

答案 0 :(得分:-1)

如果“cmd”为null,则会失败(null不等于方法):

if(cmd.equals("type>box"))

尝试将其替换为:

if("type>box".equals(cmd))