• Post Reply Bookmark Topic Watch Topic
  • New Topic

Methods from ArrayList not available  RSS feed

 
Greenhorn
Posts: 3
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to add elements to an arraylist but the methods are not working;



The line that does not compile gives me the following errors; <identifier> expected, illegal start of type, package testList doesn't exist. I added a picture to make my problem more clear;
Does anyone know what i'm doing wrong?
pic.png
[Thumbnail for pic.png]
Problem
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Laura kiwi wrote:
The line that does not compile gives me the following errors; <identifier> expected, illegal start of type, package testList doesn't exist. I added a picture to make my problem more clear;


Java statements, that are not declarations, must be in constructors, methods, or initializers. It can't just be placed anywhere.

Henry
 
Greenhorn
Posts: 29
3
Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry is correct.
Here is an example.  Since you'll learn about constructors later, we'll need a main method and put your code inside it.  A main method is a common point of entry to a program:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!