Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Declare ArrayList in class

 
Andrew Machen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the error message that the compiler is giveing you?
 
Andrew Machen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caret should be at "<".
 
Henry Wong
author
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of Java are you using?

Henry
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Java version are you running?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankjavascript: x()
beerchugs, guys. Hopefully one day I'll be able to help someone out in return.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic