我正在为我的计算机应用程序内部评估准备一个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();
}
}请尽快回复possible.Please.....
发布于 2013-10-27 20:08:37
如果"cmd“为null,这将失败(null没有equals方法):
if(cmd.equals("type>box"))尝试将其替换为:
if("type>box".equals(cmd))https://stackoverflow.com/questions/19617822
复制相似问题