Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 5, 2009, 02:50 PM   #1
davidlt
macrumors member
 
Join Date: May 2007
Location: Lithuania
10.6 + JAVA = not working?

Okay, it is first time after 10.6 upgrade on 10.5 I used JAVA on this Mac. And it did not work. So I went Sun page for tutotial. Here is the program:
Code:
//A Very Simple Example
class ExampleProgram {
  public static void main(String[] args){
    System.out.println("I'm a Simple Program");
  }
}
Saved it to "ExampleProgram.java".

When:
javac ExampleProgram.java
java ExampleProgram

Got:
Exception in thread "main" java.lang.NoClassDefFoundError: ExampleProgram
Caused by: java.lang.ClassNotFoundException: ExampleProgram
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
at java.lang.ClassLoader.loadClass(ClassLoader.java:254)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:399)

And it's the same for every JAVA program. What's wrong? Anyone see?
davidlt is offline   0 Reply With Quote
Old Nov 5, 2009, 03:33 PM   #2
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
worked fine for me on 10.6. Maybe try:
java -cp . ExampleProgram

to see if . isn't in your default classpath? I can't imagine why that would be.

Also, was ExampleProgram.class generated in your current directory?

-Lee
lee1210 is offline   0 Reply With Quote
Old Nov 5, 2009, 03:55 PM   #3
chown33
macrumors 603
 
Join Date: Aug 2009
Define your class as:

Code:
public class ExampleProgram {
It should work without public (and it does work here), but it's not a good idea.


Make sure you don't have a CLASSPATH environment variable defined. Execute this Terminal command:

Code:
printenv | sort
Copy and paste the output into a reply post.
chown33 is offline   0 Reply With Quote
Old Nov 5, 2009, 10:41 PM   #4
davidlt
Thread Starter
macrumors member
 
Join Date: May 2007
Location: Lithuania
a) "public" does not change anything.
b) Yeah, it looks I do have CLASSPATH set to CLASSPATH=/Users/david/.resolver somewhy.
c) java -cp . ExampleProgram works.

Yeah, it's a DocBook thing. Uninstalling DocBook fixed it.
davidlt is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Java not working on new mac, what to do? Nerooo Mac Basics and Help 5 Dec 15, 2013 06:37 AM
Java Not working 10.8.3 hcri50 OS X 10.8 Mountain Lion 5 Mar 21, 2013 11:55 PM
Why is Java not working? Nermal OS X 10.8 Mountain Lion 7 Feb 2, 2013 03:29 AM
Java not working kittycatrock Mac Basics and Help 4 Feb 1, 2013 10:08 AM
Java 1.5 not working in OS X 10.8 xedod OS X 10.8 Mountain Lion 8 Aug 8, 2012 01:27 PM

Forum Jump

All times are GMT -5. The time now is 12:10 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC