Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

LOST1000

macrumors newbie
Original poster
Oct 24, 2010
8
0
First and foremost, thanks in advance.

My program is suppose to have balls bouncing off the walls, changing colors each time they do so. I'm not sure what the issue is, however I am getting the following errors:



Ball.java:19: not a statement
addMouseListener{
^
Ball.java:19: ';' expected
addMouseListener{
^
Ball.java:76: invalid method declaration; return type required
public BallThread(int xCoord, int yCoord)
^



I can't figure out with the problem is, so any and all help is greatly appreciated.

Again, thanks in advance.


Code
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
If addMouseListener is intended to be a function declaration it probably needs a return type and argument list...

Alternatively, you could be missing a semicolon somewhere before that, as it mentions.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,706
8,346
A sea of green
Where are you learning this from: a book, an online tutorial, an example you're modifying, a class you're attending? The isn't something I'd expect anyone to write from nothing.

Whatever you're learning from, you've made a major mistake on line 20, with this code:
Code:
                addMouseListener{
If you intended that to be a call to a method addMouseListener, then the {}'s need to be ()'s instead. If you intended something else, you'll have to explain what you intended. If you don't know what you intended, then at least tell us what you're learning from and be specific: book title and author; tutorial URL, example URL, class description.

When the code is that far wrong, it's not always possible to discern the intent just by reading the code. So I suggest that you describe what you intend the code starting at line 20 to be and do.
 
Last edited:

LOST1000

macrumors newbie
Original poster
Oct 24, 2010
8
0
It's a class assignment sourced from a number of places, but mainly examples from class (beginners java).

You were right about the brackets - I see what I did there. Changing it cut out my two initial errors.

new code

I am still getting this error, not exactly sure what it's asking me to do.

Ball.java:75: invalid method declaration; return type required
public BallThread(int xCoord, int yCoord)

Thanks again.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
It's a class assignment sourced from a number of places, but mainly examples from class (beginners java).

You were right about the brackets - I see what I did there. Changing it cut out my two initial errors.

new code

I am still getting this error, not exactly sure what it's asking me to do.

Ball.java:75: invalid method declaration; return type required
public BallThread(int xCoord, int yCoord)

Thanks again.

The error message says "return type required".

So what are the parts of a method declaration: There must be a name. There can be parameters, but they are not required. What else could there be that is actually required? Look at the error message. A big, big, big hint.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.