Java 使用 parse.string 返回字符串输入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19202622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Return string Input with parse.string
提问by Makominami
I'm having an issue with a java program trying to get a string input from a joptionpane menu with a prompt box. With returning a string input. I don't know if im going about it all wrong by trying to use
我在尝试从带有提示框的 joptionpane 菜单中获取字符串输入的 java 程序遇到问题。返回一个字符串输入。我不知道我是否通过尝试使用来解决所有问题
String.parseString(input)
Im very much a beginner with this so any help would have to be as simple as possible or a correction outright.
我是一个初学者,所以任何帮助都必须尽可能简单或彻底纠正。
private static String getStringInput (String prompt) {
String input = EZJ.getUserInput(prompt);
return String.parseString(input);
}
UseCalls.java:27: error: cannot find symbol
return String.parseString(input);
^
symbol: method parseString(String)
location: class String
1 error
Here is a sample of the menu Im trying to use it with
这是我尝试使用的菜单示例
do {
userInput = mainMenu();
if (userInput.equals("1")) {
String name = getStringInput("Name?");
String address = getStringInput("Address?");
call[numCalls++] = new Call();
}
} while (!userInput.equals("0"));
}
Here is the EZJ mini method
这是 EZJ 迷你方法
public class EZJ {
public static String getUserInput (String prompt) {
return JOptionPane.showInputDialog(prompt);
}
public static void dialog(String inputValue) {
JOptionPane.showMessageDialog ( null, inputValue );
}
}
采纳答案by Computoguy
You don't need to parse the string, it's defined as a string already.
您不需要解析字符串,它已经定义为字符串。
Just do:
做就是了:
private static String getStringInput (String prompt) {
String input = EZJ.getUserInput(prompt);
return input;
}
回答by Valerij Bielskij
As you see in an error UseCalls.java:27: error: cannot find symbol
return String.parseString(input);
there is no method parseString
in String
class. There is no need to parse it as long as JOptionPane.showInputDialog(prompt);
already returns a string.
正如您在错误中看到的那样,类中UseCalls.java:27: error: cannot find symbol
return String.parseString(input);
没有方法。只要已经返回一个字符串就不需要解析它。parseString
String
JOptionPane.showInputDialog(prompt);
回答by sahil dhawan
If you're really bent upon converting Integer to String value, I suggest use String.valueOf(YourIntegerVariable). More details can be found at: http://www.tutorialspoint.com/java/java_string_valueof.htm
如果您真的很想将整数转换为字符串值,我建议使用 String.valueOf(YourIntegerVariable)。可以在以下位置找到更多详细信息:http: //www.tutorialspoint.com/java/java_string_valueof.htm