Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

classFormatException error in hello world example?

7 views
Skip to first unread message

BenTaylor

unread,
Feb 9, 2007, 10:50:38 AM2/9/07
to comp.lang.java.programmer
i'm trying to run the very simple example at
[url]http://java.sun.com/docs/books/tutorial/getStarted/cupojava/
unix.html[/url]
having installed the jdk for linux from java.sun.com's downloads
section,
and I've done it exactly as described but it gives me this error:

[ben@benlinux helloworld]$ java HelloWorldApp
Exception in thread "main" java.lang.ClassFormatError: HelloWorldApp
(unrecognized class file version)
at java.lang.VMClassLoader.defineClass(libgcj.so.7rh)
at java.lang.ClassLoader.defineClass(libgcj.so.7rh)
at java.security.SecureClassLoader.defineClass(libgcj.so.7rh)
at java.net.URLClassLoader.findClass(libgcj.so.7rh)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at gnu.java.lang.MainThread.run(libgcj.so.7rh)

any ideas what could be the problem?

cheers

Oliver Wong

unread,
Feb 9, 2007, 10:55:54 AM2/9/07
to
"BenTaylor" <ben.j.t...@hotmail.co.uk> wrote in message
news:1171036238.5...@p10g2000cwp.googlegroups.com...

It's basically saying that the java interpreter is unable to read the
compiled program. This may be because your compiler targets a different
version of Java than your interpreter, or because some mistake occurred
while compiling leading to a corrupt file.

How did you compile the Java program?

- Oliver


BenTaylor

unread,
Feb 9, 2007, 11:22:14 AM2/9/07
to
On 9 Feb, 15:55, "Oliver Wong" <o...@castortech.com> wrote:
> "BenTaylor" <ben.j.taylo...@hotmail.co.uk> wrote in message
> - Oliver- Hide quoted text -
>
> - Show quoted text -

I did it using "javac HelloWorldApp.java".


Could it be that it's somehow trying to compile with gcc, and run with
JDK - or the other way round? I thought that could be the problem but
i don't know enough about java to find out or fix it. But surely
"java" and "javac" are both JDK programs ... aren't they? Or could it
be using the version of "java" to run it that it previously had
installed, rather than the JDK version?

BenTaylor

unread,
Feb 9, 2007, 11:28:39 AM2/9/07
to
> installed, rather than the JDK version?- Hide quoted text -

>
> - Show quoted text -

Ah, i've solved it - for some reason /usr/bin/java was pointing to /
etc/alternatives/java instead of /usr/java/default/bin/java.
Thanks for the input

Nigel Wade

unread,
Feb 9, 2007, 11:32:43 AM2/9/07
to
BenTaylor wrote:

It looks like your system has a conflict between the Sun Java installation and
an existing gcj installation.

Check exactly what executable the "java" command runs (and also javac). It might
be that you've used a recent Sun SDK javac compiler to create the classes, but
the java command is an older version of java (from gcj).

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : n...@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555

Lew

unread,
Feb 9, 2007, 2:52:14 PM2/9/07
to
BenTaylor wrote:
> Ah, i've solved it - for some reason /usr/bin/java was pointing to /
> etc/alternatives/java instead of /usr/java/default/bin/java.
> Thanks for the input

Or instead of updating /etc/alternatives/ to point to the latest java.

The "some reason" is that the alternatives mechanism is the cleanest way to
maintain versions, and allows different users / processes to use different
versions.

- Lew

0 new messages