This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How do  display the contents of List<> Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How do  display the contents of List<>" Watch "How do  display the contents of List<>" New topic
Author

How do display the contents of List<>

Nimu Chox
Greenhorn

Joined: Mar 11, 2012
Posts: 27
I am new to this
I created the method that is intended to display all the contents in an array:

public List<Customer> findAll() {

for (Customer customerElement : CustomerList)
{
System.out.println( customerElement );
}

}

"Error : Missing statement"


I have tried to change to the following:
public customer findAll() {

for (Customer customerElement : CustomerList)
{
System.out.println( customerElement );
}

}
but still the same error, please help.


Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 4749
    
    7

Nimu Chox wrote:I created the method that is intended to display all the contents in an array:
...
"Error : Missing statement"...

I suspect you're getting a lot more information than just that. Please provide the entire stack trace exactly as it was produced.

Also, please UseCodeTags (←click).

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Nimu Chox
Greenhorn

Joined: Mar 11, 2012
Posts: 27
PrintAll() is complaining return type is missing, thanks in advance
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 4749
    
    7

Nimu Chox wrote: PrintAll() is complaining return type is missing, thanks in advance

Actually, I think you mean findAll(), and I suspect that it's complaining that you're NOT returning anything, not that the return type is missing.

As I said before, please post the exact message you are getting (all of it).

And also: fields and methods should start with a lowercase letter. It's not a language requirement, but it is an established convention, so you should stick to it.

Winston
James Boswell
Ranch Hand

Joined: Nov 09, 2011
Posts: 657
    
    2

Check the return type defined for findAll() method and then take a look at your implementation of it.
Nimu Chox
Greenhorn

Joined: Mar 11, 2012
Posts: 27
Thanks alot. One more thing, How can I print the "stack trace" of my program?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 4749
    
    7

Nimu Chox wrote:Thanks alot. One more thing, How can I print the "stack trace" of my program?

Well, usually you do it when you get an Exception, in which case it's {name-of-Exception}.printStackTrace(), but you can also print it out for the current Thread via Thread.currentThread().

However, if you got an error when you compiled, the message you already posted will have been part of a larger stack trace that includes method names and line numbers. Just copy and paste that.

Winston
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How do display the contents of List<>
 
Similar Threads
non-static method cannot be referenced from a static context
Calling method from another class
reading input from a file into a array
trying to call a method but cannot find symbol
help with database!