Hi all, I've been doing some java programing, I created a tester class for a project and when i try to output something to the terminal window i get a 'null pointer exception', any help would be appreciated, many thanks.
All the code needed has been uploaded.
*Extra info
- I get the null pointer exception when i call the method within the tester class.
The null pointer exception points to the 'getAllRallies()' Method in the Club class
public String getAllRallies ()
{
String r = "";
for (int index = 0; index < allRallies.size(); index++)
{
Rally m = allRallies.get(index);
r += m.getAsString();
}
return r;
}
The Main is not there because I'm using blue J which creates the Main for you.
I'm confused i don't understand what tags your talking about, is that to do with the way the forum shows the code or are you saying i need to do something with the code :S
Look at the JavaDocs for HashMap. Your code is trying to iterate the HashMap using an index and that's not the way you loop through the HashMap members.
Code:
public String getAllRallies ()
{
String r = "";
for (int index = 0; index < allRallies.size(); index++)
{
Rally m = allRallies.get(index);
r += m.getAsString();
}
return r;
}
Instead, you would do something like this:
Code:
public String getAllRallies ()
{
String r = "";
Set set = allRallies.entrySet();
Iterator i = set.iterator();
while(i.hasNext()){
Map.Entry me = (Map.Entry)i.next();
Rally m = (Rally) me.getValue();
r += m.getAsString();
}
return r;
}
The Main is not there because I'm using blue J which creates the Main for you.
And this is why nobody should use BlueJ.
Somebody got the bright idea of obfuscating what is really happening for students to try and get them to focus on the code / methods they write. When these same students have to write real code and run it elsewhere, or set up an environment, they fall flat on their face.
The code tags that he is talking about are called BBCode (google them for the markup standard). They start with a "[" and end with a "]" and have the word "code" inbetween. They work like XML markup and need a closing tag as well with the "/" before the word.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.