aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Cannot get code with assertions to compile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Cannot get code with assertions to compile" Watch "Cannot get code with assertions to compile" New topic
Author

Cannot get code with assertions to compile

Chiran Mathur
Ranch Hand

Joined: Feb 07, 2001
Posts: 63
Do I need to import any particular package for assertions to work. I am using JBuilder 7 and it is uisng JDk1.4.0 and it just doesn't recognize the word assert.
Chiran Mathur
Ranch Hand

Joined: Feb 07, 2001
Posts: 63
package assertUse;
import java.util.*;
import java.io.*;
import java.lang.Error.*;
public class AssertTest{
public void methodA(int i) throws AssertionError{
assert i < 1024 : "Invalid Value";
}
}
I always get this error while compilingthe above code:
"assertUse.java": Error #: 200 : ';' expected at line 7, column 18
Sridhar Srikanthan
Ranch Hand

Joined: Jan 08, 2003
Posts: 366
Chiran,
one possible problem might be the way you are compiling the code.
In order for the code with assertions to be compiled, you have to type
javac -source 1.4 AssertTest.java
I tried the same code and it compiles just fine
Hope this helps
Sri
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot get code with assertions to compile