• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Declare ArrayList in class

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>();

}
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Caret should be at "<".
 
author
Posts: 23936
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Java version are you running?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankjavascript: x()
beerchugs, guys. Hopefully one day I'll be able to help someone out in return.
 
Everyone is a villain in someone else's story. Especially this devious tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic