troubleshooting Question

"Could not find or load main class" Java runtime error

Avatar of Ahmet Ekrem SABAN
Ahmet Ekrem SABANFlag for Austria asked on
JavaWindows 8Java App ServersJava EE
73 Comments1 Solution2794 ViewsLast Modified:
Hello!

I am trying to use JNA, but can obviously not see a simple problem. The code is a simple example I got from here. Unfortunately, I got my wires crossed and cannot see where the problem is. I searched the Web and found several sites where a solution is tried to be found for the problem, but no avail. :-(

To reduce the problem to its essentials, I use the command prompt in Windows 8.1 and do the following:
D:\Projekte\C>type *

ctest.c


/* ctest.c */

#include <stdio.h>

void helloFromC() {
    printf("Hello from C!\n");
}
D:\Projekte\C>gcc -o libctest.so -shared ctest.c

D:\Projekte\C>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\Projekte\C

2014-10-22  15:05    <DIR>          .
2014-10-22  15:05    <DIR>          ..
2014-10-21  16:02                93 ctest.c
2014-10-22  15:05            21.804 libctest.so
               2 Datei(en),         21.897 Bytes
               2 Verzeichnis(se), 490.275.999.744 Bytes frei

D:\Projekte\C>copy lib*.* ..\Java
libctest.so
..\Java\libctest.so überschreiben? (Ja/Nein/Alle): j
        1 Datei(en) kopiert.

D:\Projekte\C>cd ..\Java

D:\Projekte\Java>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\Projekte\Java

2014-10-22  15:05    <DIR>          .
2014-10-22  15:05    <DIR>          ..
2014-10-22  13:20               354 HelloWorld.java
2014-10-21  16:50           946.973 jna-3.2.5.jar
2014-10-22  15:05            21.804 libctest.so
               3 Datei(en),        969.131 Bytes
               2 Verzeichnis(se), 490.275.999.744 Bytes frei

D:\Projekte\Java>type HelloWorld.java
/* Hello World! */

import com.sun.jna.Library;
import com.sun.jna.Native;

public class HelloWorld {
    public interface CTest extends Library {
        public void helloFromC();
    }
    static public void main(String argv[]) {
        CTest ctest = (CTest) Native.loadLibrary("ctest", CTest.class);
        ctest.helloFromC();
    }
}

D:\Projekte\Java>javac -classpath jna-3.2.5.jar HelloWorld.java

D:\Projekte\Java>java -classpath jna-3.2.5.jar:. HelloWorld
Fehler: Hauptklasse HelloWorld konnte nicht gefunden oder geladen werden

D:\Projekte\Java>

The runtime error reads in English Error: Could not find or load main class, in German Fehler: Hauptklasse HelloWorld konnte nicht gefunden oder geladen werden.

Where do you think I is the problem? As you can see, the code compiles properly.

Thank you in advance!
Hello-JNA-World.png
JNA-Hello-World.PNG
ASKER CERTIFIED SOLUTION
Duncan Roe
Software Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 73 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 73 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros