This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
If you use System.out.println() to print an Inbox object, like this:
Inbox box = new Inbox(); System.out.println(box);
then println calls (indirectly) the method Inbox.toString() and displays the String that the method returns. Every class inherits a version of toString() from java.lang.Object which returns the class name, followed by the '@' character, followed by the result of calling the hashCode() method. If your class doesn't have a toString() method, then this inherited version is called.
So to fix this, you might give Inbox a method like
which, if Inbox has a member variable "name" that holds the user's name and one named "count" that holds the number of messages, will print something like
Is MessageList an array or an ArrayList? Your 'for' construct called the size() method of an ArrayList, but in the body you are calling the elements of an array using MessageList[i]. Which is it?
If MessageList is an array, then change your 'for' construct to use MessageList.length instead of MessageList.size(). (**Note there are no "()" after length as it is a property of an array and not a method). My guess is that your problem is here.
If MessageList is an ArrayList, then change the way you call elements from MessageList[i] to MessageList.get(i).