• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • paul wheaton
  • Paul Clapham
Saloon Keepers:
  • Piet Souris
Bartenders:

Error ')' or ',' expected

 
Ranch Hand
Posts: 59
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An error ')' or ',' expected error seems straight-forward but has stumped me since last evening.

Trying all known fixes, I think perhaps a second or third set of eyes might see the error.

Enclosed is a code segment with the line 15  (or a close line) throwing the error:



Thanks
 
Master Rancher
Posts: 5152
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you compiling the code?  If you use the javac command it gives this error message with ^ showing where the error is:
 
Marshal
Posts: 81757
593
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mat Dif wrote:. . . Trying all known fixes, I think perhaps a second or third set of eyes . . .

You might have seen it yourself if you had indented your code correctly. The long lines make it very difficult to read. Look in the old Sun style guide, which tells you about line lengths. Keep your lines not more than 80 characters, in monospaced type. I have corrected your code to shorten the lines and remove unnecessary whitespace and got the following:-You appear to be using five spaces per indentation level, which is too many; stick to three or four. And get your text editor to convert tabs to spaces automatically. I haven't corrected that problem. At least you aren't using tabs.
Look at line 4. It has a ( in its middle. There isn't a corresponding ) to finish your method call. The anonymous class should finish with a }, followed by ); to complete the method call. The if, now line 17, appears to the javac tool to be part of the anonymous class, and the syntax doesn't make sense.
Search my posts for writing backwards. What you do is start the method callThen add the listener:-Then fill in the methods:-
I don't like the indentation type with } starting the line, then if, then { to finish the line. I would prefer to see the if as a line by itself.
Are you aware of classes called XYZAdapter? Each XYZListener with more than one method has a corresponding class called XYZAdapter. You only need to implement the methods you actually need, but be sure to check for spelling errrors by using @Override.
 
Campbell Ritchie
Marshal
Posts: 81757
593
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please decide where you want the if. It might never be called where it is. If you want it called when something happens to the mouse, put the if into another method in the anonymous class and call that method from another method.
 
Bartender
Posts: 29040
214
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Back when I worked developing code for the Macintosh, co-workers would exploit the fact that modern monitors could display lots of text to produce code with up to 100 characters or mode in a line.

I hated this because, for one thing, if you printed that sort of stuff and you didn“t have a tiny enough font applied, the code would run off the edge of the paper.

My own preference for line length is 65 characters. It's actually shaped from the ancient days when I had to code on punched cards. Although standard IBM cards ran to 80 columns, most programming languages reserved up to 8 characters for a sequence number. If you dropped the deck, a quick run through a sorting machine would put them back in the right order. Some languages carved out additional zones, hence 65 instead of 72.

This carried over to when we got terminals with full-screen editors. The standard for programming terminals was for a long time 24 rows x 80 columns. The text editors here would generally prefix or suffix the edit text with a zone where you typed in editing commands.

The days are mostly behind us now, but there are still good reasons to keep line lengths from running off into infinity.
 
Mat Dif
Ranch Hand
Posts: 59
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:How are you compiling the code?  If you use the javac command it gives this error message with ^ showing where the error is:



NetBeans/Maven

Thanks.
 
Mat Dif
Ranch Hand
Posts: 59
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please decide where you want the if. It might never be called where it is. If you want it called when something happens to the mouse, put the if into another method in the anonymous class and call that method from another method.



Thank you for your reply. I'm going to begin looking into this tonight and will post back here should I have questions.

-Matthew
 
Campbell Ritchie
Marshal
Posts: 81757
593
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:. . .

Where did that code come from? I can't find it.
 
Norm Radder
Master Rancher
Posts: 5152
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made it as an example for the compiler to give a missing ) message.
The OP had said:

with the line 15  (or a close line) throwing the error:


I wondered if he could locate the error more closely than that.
 
Campbell Ritchie
Marshal
Posts: 81757
593
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The } that completes the anonymous class is at the beginning of OP's line 15. That requires ); following to complete the method call. The remainder of that line (if ...) now seems to be dangling somewhere and, assuming it compiles in the first place, is probably impossible to call from anywhere.
 
Saloon Keeper
Posts: 5787
221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the situation where you create an anonymous class (what you do with "addMouseMouseMotionListener(...)" is to align all your parantheses and braces. So like:

then you see at once what Campbell refers to.
   
 
reply
    Bookmark Topic Watch Topic
  • New Topic