*
The moose likes Beginning Java and the fly likes Declare ArrayList in class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Declare ArrayList in class" Watch "Declare ArrayList in class" New topic
Author

Declare ArrayList in class

Andrew Machen
Greenhorn

Joined: Mar 08, 2006
Posts: 4
Hi guys -

New to the board. Please forgive if my post isn't in the right place.

I'm trying to declare an ArrayList in a class, instantiating in the constructor. My syntax is obviously wrong at the last line. Any suggestions? Thanks in advance.

public class InvoiceRecord {

private Header HeaderLine;
private List HdrCommentLines;
private List DetailLines;
private List DetCommentLines;


InvoiceRecord() {
//errorHdrCommentLines = new ArrayList<HeaderComments>();

}
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Hi Andrew, welcome to JavaRanch!

Did you import java.util.List and java.util.ArrayList?

Are classes available for Header and HeaderComments?

If these don't fix it, please post your error message.
[ March 08, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

Welcome to JavaRanch!

Although it would be far better if the member HdrCommentLines were parameterized, I don't see anything technically wrong with this (as long as the class HeaderComments exists, of course.)


[Jess in Action][AskingGoodQuestions]
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
What is the error message that the compiler is giveing you?


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Andrew Machen
Greenhorn

Joined: Mar 08, 2006
Posts: 4
My error is - syntax error - "(" expected. Caret at error, shown below:

HdrCommentLines = new ArrayList<HeaderComments>();
^

I have "import java.util.*;", which should take care of things. (guess not)
Andrew Machen
Greenhorn

Joined: Mar 08, 2006
Posts: 4
Caret should be at "<".
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18529
    
  40

What version of Java are you using?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
What Java version are you running?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Originally posted by Andrew Machen:
Caret should be at "<".


Ah. OK, the problem is that generics (the feature that involves those angle brackets) was introduced in Java 5 (JDK 1.5, called "Tiger") and you're apparently user an older version of the Java compiler. You can get a newer JDK for free from java.sun.com.
Andrew Machen
Greenhorn

Joined: Mar 08, 2006
Posts: 4
Thankjavascript: x()
beerchugs, guys. Hopefully one day I'll be able to help someone out in return.
 
 
subject: Declare ArrayList in class
 
Similar Threads
Clustering an application by jboss produced this:
How can final and transient be used in a variable declaraion?
backBean add to list Problem
in function using PreparedStatement create performance problem or not?
Generics in Java