[英]Inputting a string into my code that an int is required and I get a java error how can I fix this?
[英]java - How can I fix this “error: array required, but String found” error in my server class for my University directory?
这是代码的摘录。
while(true) {
System.out.print("Enter New Command: ");
Scanner scan = new Scanner(System.in);
String myLine = scan.nextLine(); //finds out whether command is to add,find, or delete
String[] splitInfo = myLine.split(" ");
if (myLine[0].equals("find")) { //*****ERROR********
d.find(myLine[1]); //*****ERROR HERE******
}
我记下了我的错误发生在哪几行。 我在做什么错,应该如何解决?
myLine
是您的String, splitInfo
您的数组。 你必须改变
if (myLine[0].equals("find")) {
d.find(myLine[1]);
}
至
if (splitInfo[0].equals("find")) {
d.find(splitInfo[1]);
}
问题是if (myLine[0].equals("find"))
。
应该是if (splitInfo[0].equals("find"))
。
请注意, d.find(myLine[1]);
还应该更改为d.find(splitInfo[1]);
。
这将修复它
while(true) {
System.out.print("Enter New Command: ");
Scanner scan = new Scanner(System.in);
String myLine = scan.nextLine();
String[] splitInfo = myLine.split(" "); //The array which has tokens of myline
if (splitInfo[0].equals("find")) { //look for 'find' in splitInfo
d.find(splitInfo[1]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.