0

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.

Community
  • 1
  • 1
JessNicole27
  • 63
  • 1
  • 7

4 Answers4

3

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.

M A
  • 71,713
  • 13
  • 134
  • 174
1

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
Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
  • It is like that in my program but I could not get it to show up right on here – JessNicole27 Oct 03 '14 at 19:21
  • it says this --> private ArrayList array; in my program but on this site when I was typing in my question it would not show the String part so I put it in parentheses to show I actually has the String part in my program – JessNicole27 Oct 03 '14 at 19:22
  • JessNicole27 already said "it actually has these symbols <> around the String sections". – timrs2998 Oct 03 '14 at 19:23
  • @user1509183 here I see parentheses not <> private ArrayList(String) array; – Kick Buttowski Oct 03 '14 at 19:25
1

your array declaration should be like this:

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

import

 import java.util.ArrayList;
Rustam
  • 6,485
  • 1
  • 25
  • 25
1

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.

timrs2998
  • 1,612
  • 18
  • 14