> Please help, have to hand in 2 hours time....
>
[quoted text clipped - 20 lines]
> return true;
> }

Signature
monique
Help us help you:
http://www.catb.org/~esr/faqs/smart-questions.html
Thanks for helping,
This is the beginning of the code for PlayList:
public class PlayList implements SongList
{
private ArrayList<Song> playlist;
private int playListCount;
/**
* Constructor
*/
public PlayList(){
playListCount = 0;
playlist = new ArrayList<Song>();
}
....
}
This is the beginning of SongList
public interface SongList{}
This is the beginning of Song object:
public class Song implements Comparable<Song>{}
I think I haven't quite catch the meaning of interface, implememnt and
foreach
Is this enough for you to help? If not I will post all of it
million thanks
Honyin
> > Please help, have to hand in 2 hours time....
> > I don't understand what the error message means and how to change it
> > Thanks million in advance
> > Error message selecting the first for(Song s : list): foreach not
> > applicable
> > to expression type
> > Code:
> > public boolean merge(SongList list) throws NullPointerException
> > {
> > ArrayList<Song> playlist2 = playlist;
> > boolean testing = true;
> > for(Song s : list)
> > if(!playlist2.add(s)) // in case if add has error, it will not
> > change playlist
> > testing = false;
> > if(testing==false) throw new NullPointerException("Error in:
> > merge");
> > for(Song s : list)
> > playlist.add(s);
> > return true;
> > }
> The problem is in the code you didn't post:
> What's a SongList? Do you think it's in some way related to playlist
> or playlist2?
> monique
> Help us help you:
> http://www.catb.org/~esr/faqs/smart-questions.html
Hendrik Maryns - 21 Apr 2006 13:39 GMT
Please do not top-post. See my comments interspersed with your post.
And you might want to check for your newsreader inserting unwanted newlines.
Honyin Hau schreef:
> Thanks for helping,
>
[quoted text clipped - 5 lines]
>
> private ArrayList<Song> playlist;
Use List<Song> instead: do not code to implementations, code to an
interface.
> private int playListCount;
>
[quoted text clipped - 9 lines]
>
> playlist = new ArrayList<Song>();
But this stays the same!
> }
>
[quoted text clipped - 14 lines]
>
> Honyin
>>> Please help, have to hand in 2 hours time....
>
[quoted text clipped - 18 lines]
>
>>> for(Song s : list)
You can only use the foreach syntax on objects that implement the
Iterable interface. SongList does not:
> This is the beginning of SongList
>
> public interface SongList{}
So either do
public interface SongList extends Iterable { ... }
or do your iteration manually.
>>> if(!playlist2.add(s)) // in case if add has error, it will not
>>> change playlist
Bad style.
>>> testing = false;
>
>>> if(testing==false) throw new NullPointerException("Error in:
>>> merge");
Huh? Why a NullPointerException? I don’t see any null pointer
anywhere. Do not abuse RuntimeExceptions.
>>> for(Song s : list)
>
>>> playlist.add(s);
You could make you code more legible by inserting {} around the commands
after if and for statements.
>>> return true;
>
>>> }
And please do read the useful link Monique gave you:
>> http://www.catb.org/~esr/faqs/smart-questions.html
H.
- --
Hendrik Maryns
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html