java - 基本java程序找不到符号错误

标签 java arraylist cannot-find-symbol

我需要这个基本程序的帮助。我的 friend 给了我大部分代码,但没有给我导入语句。到了最后,它写着list.add(finalCombined.get(counter3)); ,它给了我一个错误。我得到的错误是

Cannot find Symbol 
Symbol: variable list
location: class ArrayUtils

我对此感到非常困惑。我添加了我认为需要的导入语句。谢谢

import java.util.ArrayList;
import java.util.Random;
import java.util.Collections;
import java.lang.String;

public class ArrayUtils {
    public void randomStrings(ArrayList<String> arrayList,int nbrOfStrings,int vowelCnt, int strSize){
        ArrayList <String> finalCombined = new ArrayList();
        ArrayList <String> finalCombined = new ArrayList();
        for (int cnt = 0; cnt < nbrOfStrings; cnt++)
        {
            int cnt2 = 0;
            int gn, size, vowelUsed;
            Random n1 = new Random();
            size = 122-96;
            //char cs[] = new char[strSize];
            //String cs;
            //cs = "";
            ArrayList <Character> cs = new ArrayList();
            int counter = 0;
            vowelUsed = 0;

            while (counter < 1)
            {
                vowelUsed = n1.nextInt(vowelCnt + 1);
                if (vowelUsed == 0)
                {
                }
                else
                {
                    counter = 2;
                }

            }

            while (cnt2 < (strSize - vowelUsed))
            {
                gn = n1.nextInt(size) + 97;

                if (gn == 97 | gn == 101 | gn == 105 | gn == 111 | gn == 117 | gn == 121)
                {
                }

                else
                {
                    cs.add((char)gn);
                    //cs += ((char)gn + "");
                    cnt2 ++;
                }
            }
            while (cnt2 < strSize)
            {
                gn = n1.nextInt(size) + 97;
                if (gn == 97 | gn == 101 | gn == 105 | gn == 111 | gn == 117 | gn == 121)
                {
                    cs.add((char)gn);
                    //cs += ((char)gn + "");
                    cnt2 ++;
                }
            }
            //int check;
            //check = list.add(cs[cnt]);
            Collections.shuffle(cs);

            String combined;
            combined = "";
            //System.out.println(cs);

            int counter2 = 0;
            while (counter2 < strSize)
            {
                combined += cs.get(counter2); 
                counter2 ++;
            }
            finalCombined.add(combined);
            counter2 = 0;
            combined = "";

        } // end # strings    

        for (int counter3 = 0; counter3 < nbrOfStrings; counter3++)
        {
            list.add(finalCombined.get(counter3));
        }

    } // end method
}

最佳答案

list.add(finalCombined.get(counter3));

您尚未声明任何名为 list 的变量,因此该行无法通过编译。

也许你的意思是

arrayList.add(finalCombined.get(counter3));

因为您的 randomStrings 方法有一个名为 arrayList 的参数,您根本没有使用该参数。

关于java - 基本java程序找不到符号错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29649726/

相关文章:

java - Kafka 模式订阅。新主题未触发再平衡

java - 了解泛型以及类型检查的工作原理

java - 我正在尝试使用 servlet 在文本文件中附加文本,这会出现错误

java - “找不到符号”或“无法解析符号”错误是什么意思?

java - 将 Eclipse 项目从 Windows 迁移到 Ubuntu 后,Eclipse 在所有地方显示 "cannot be resolved"编译错误

java - Lombok 不生成 RequiredArgsConstructor 和 AllArgsConstructor

java - 有没有办法将列表中的所有内部对象提取到新列表

java - Head First Java 书籍战舰游戏

java - 当使用 ArrayList(Collection<? extends E> c) 作为复制构造函数时,我收到两个错误