• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot get code with assertions to compile

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic