简体   繁体   中英

Cannot Find Symbol in ArrayList

I'm writing a java class and I keep hitting an error.

Paragraph.java:21: error: cannot find symbol
ArrayList array;
^
symbol: class ArrayList
location: class Paragraph

Paragraph.java:32: error: cannot find symbol
array = new ArrayList();
...................^
symbol: class ArrayList
location: class Paragraph

I imported the java class arrays at the very top of my program and it looks like this.

import java.util.Arrays;

The exact part of code I'm having errors with is...

private ArrayList<String> array;
public Paragraph()
   {
       array = new ArrayList<String>();
   }

This is part of an assignment were I have to use ArrayList.

Instead of having parentheses you should use <>

private ArrayList(String) array;

change to

private ArrayList<String> array;

your import is wrong for ArrayList

java.util.Arrays

change to

java.util.ArrayList

You should import java.util.ArrayList , not java.util.Arrays . Arrays doesn't seem to be used in your program and these are two completely different classes.

your array declaration should be like this:

 private ArrayList<String> array;
 public Paragraph()
 {
           array = new ArrayList<String>();
  } 

import

 import java.util.ArrayList;

Your problem is that the Arrays class you imported is not the ArrayList class. You need to have import java.util.ArrayList; at the top instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM