Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assertion

 
MI Mohammed
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody tell me what is the mode for javac, when compilin codes with assertions. I tried it and what i got was a compiler error and warning but when i compile the same code with javac -source 1.4, it compilled. :roll:
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have it right. You must specify -source 1.4 to compile assertions with the Java 1.4 compiler.
 
Jesse Torres
Ranch Hand
Posts: 985
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Gershman:
You have it right. You must specify -source 1.4 to compile assertions with the Java 1.4 compiler.


How do you run the code. I successfully compiled with:

javac -source 1.4 AssertionTest.java

However when trying to run, I receive:
"Exception in thread main java.lang.NoClassDefFoundError:

I have tried running as:
java AssertionTest
java -ea AssertionTest
 
Jay Pawar
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please post your code ?
 
Jesse Torres
Ranch Hand
Posts: 985
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jay Pawar:
Could you please post your code ?




Thanks,
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your classpath set?
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Your class is inside the package scjp. So should it not be in this way ?

java scjp.AssertionTest

[ February 16, 2005: Message edited by: srini vasan ]
 
Jesse Torres
Ranch Hand
Posts: 985
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I can easily compile class with:
C:\devel\scjp> javac -source 1.4 AssertionTest.java

The preceding line successfully compiles. However the following commands generate errors:

C:\devel\scjp> java -ea AssertionTest

or

c:\devel\scjp> java AssertionTest

The following is the error that is outputed to the command window:


C:\devel\scjp>java -ea AssertionTest
Exception in thread "main" java.lang.NoClassDefFoundError: AssertionTest (wrong
name: scjp/AssertionTest)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

C:\devel\scjp>

Please help!
[ February 16, 2005: Message edited by: Jesse Torres ]
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to go to "C:\devel"
and run the java command java scjp.AssertionTest
 
Jesse Torres
Ranch Hand
Posts: 985
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by srini vasan:
try to go to "C:\devel"
and run the java command java scjp.AssertionTest


BINGO
That was the problem

I went to:
C:\devel\scjp> javac -source 1.4 Assertion.Test
C:\devel\scjp> java -ea scjp.AssertionTest
successful
C:\devel\scjp>

Thanks for your help srini.
[ February 16, 2005: Message edited by: Jesse Torres ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic