Jump to content
  • Advertisement
Sign in to follow this  
Conner McCloud

[java] assert errors

This topic is 5080 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I recently inherited a large amount of Java code from another developer, and he has used asserts in several of his files. All of those files have errors. Specifically, "Syntax error on token "assert", assert expected". This is within Eclipse, and pops up when I hover over the 'assert' keyword. I'm not terribly great with Java, and this is the first time I've encountered asserts. The syntax looks good [assert false; was the most simple one I found]. I'm using the 1.4.2 version of the SDK, and its worked fine for other projects I've done. Is there something I have to set up to get it to recognize asserts, or is there just something wrong with the code? Any help would be greatly appreciated. I'm not getting particuarly useful results through Google or the forum search, so this is my last resort. If this fails, I comment out all the asserts and move on. CM

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by retard
Dunno if you checked it out already, but you might want to check out Sun's page on using asserts in Java... it's rather helpful.

http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html

Thanks for the link, but I had already read it. That's why I'm pretty sure the syntax is correct. There was the section about whether or not assert is allowed as a variable name, but I'm not sure how that could be my problem.

CM

Share this post


Link to post
Share on other sites
Sounds like a compiler setup problem.
Quote:
from http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html

Compiling Files That Use Assertions
In order for the javac compiler to accept code containing assertions, you must use the -source 1.4 command-line option as in this example:

javac -source 1.4 MyClass.java
This flag is necessary so as not to cause source compatibility problems.

Share this post


Link to post
Share on other sites
Quote:
Original post by lucinpub
Sounds like a compiler setup problem.
Quote:
from http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html

Compiling Files That Use Assertions
In order for the javac compiler to accept code containing assertions, you must use the -source 1.4 command-line option as in this example:

javac -source 1.4 MyClass.java
This flag is necessary so as not to cause source compatibility problems.

Bah...you're right, I'm a complete idiot. I read that several times, and each time I left with the conclusion that -source 1.3 allowed asserts. Bleh.

That fixed it right up. I suppose this means I have no choice but to get back to work. Damn it. [grin]

Thanks a million.

CM

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!