嘿大家有人可能会问过这个但是我试图从用户回答中实现一个ArrayList我已经做了一些研究而且它不会这样做。这是我的代码<部分内容
public class Breed
{
public static void cross_breed()
{
// Creates 3 strings named male_breed, female_breed, and cross_breed.
String male_breed;
String female_breed;
String cross_breed;
Cross_breed crossbreed;
List<String> clist = new ArrayList<String>();
while (true) // While the male_breed is a real breed continue on with the program
{
male_breed = JOptionPane.showInputDialog("What is the breed of the male?");
if (male_breed.length() == 0) break; // Makes it so if the male dog breed wasn't entered the program will exit
if (List_Breeds.blist.containsKey(male_breed)) //If the given input of the users is on the list of breeds continue with program
{
while (true) // Loops the female breed
{
female_breed = JOptionPane.showInputDialog("What is the breed of the Female");
if (List_Breeds.blist.containsKey(female_breed)) //
{
if (male_breed.equals(female_breed)) // if both breeds are the same
{
clist.add(JOptionPane.showMessageDialog(null, "Your dog is a Purebread " + male_breed));
break; //Ends the program
}
else
{
cross_breed = male_breed.substring(0, 3) + "a" + female_breed.substring(0, 3); //If both breeds arent the same take the
clist.add(JOptionPane.showMessageDialog(null, "Your dog breed is a " + cross_breed)); // first three letters of the male_breed and inserts
break; // Ends the program // an 'A' at the end.
}
Eclipse给我一个错误说明两行
clist.add(JOptionPane.showMessageDialog(null, "Your dog is a Purebread " + male_breed));
和
clist.add(JOptionPane.showMessageDialog(null, "Your dog breed is a " + cross_breed));
表示“类型列表中的方法添加不适用于参数(void)
如果我做错了请帮助......我要做的是将品种(或品种)名称添加到arraylist中,其中将显示在第二个菜单中
答案 0 :(得分:0)
“类型列表中的方法添加不适用于参数(void)”表示您正在调用的方法 - JOptionPane.showMessageDialog(JComponent, String)
不会返回任何内容。
这是因为showMessageDialog用于显示消息,而不是捕获输入。
您需要查看JOptionPane.showInputDialog()
的各种风格,以便从用户那里获得输入。