Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I´am trying to use this for my Android project, But I get this error.

$java Finger
Exception in thread "main" java.lang.NoClassDefFoundError: Finger
Caused by: java.lang.ClassNotFoundException: Finger
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
Could not find the main class: Finger. Program will exit.

I have looked on Google and then I try this:

java -classpath .finger



But this does not work :(

I get the Java file from this page:

I only need to call it from my 'mainActivity' for my project.

My Java setup is like this:

$java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.3) (6b24-1.11.3-1ubuntu0.12.04.1)
OpenJDK Server VM (build 20.0-b12, mixed mode)


$javac -version
javac 1.7.0_07
share|improve this question
hmm I have not compiled it... do I need to do this if I only need to call the methods from my 'mainActivity'? can I not just write 'import Finger;'? – Voidcode Sep 2 '12 at 14:06
To people considering voting to close this question: This question should probably not be closed as off-topic, since it appears to fundamentally come down to what the java and javac commands do, how to use them, and what kinds of files they can be used on. Those are not really programming questions. This appears to be a question on how to use the Java software in Ubuntu, rather than how to write Java code, so it would be considered on-topic for our site. – Eliah Kagan Sep 2 '12 at 17:59
Ok sorry if this is too easy for this site. I have make a lot of java-code but I use Eclipse, I has never needed to think about compiled commands before now. The reason I try two run it in the terminal is to secure me that class work. The file is an simple-program so I will my change it to return the output-data as string(but this is not an part of my question).. Ok now I have try compiled 'javac' so the compiled-file is 'Finger.class'. Then I get this error( look it up, and I only need to changes the JRE to openJDK-7 and then it runs:) – Voidcode Sep 2 '12 at 19:26
Thank :) you got me thinking in the right direction.. – Voidcode Sep 2 '12 at 19:32
I'm glad the problem is solved. I've posted an answer detailing the solution for the first problem (which is what you posted the question about). – Eliah Kagan Sep 2 '12 at 19:51
up vote 4 down vote accepted

As discussed in comments... is a Java source code file. .java source code files cannot be run in that form; they must first be compiled.

As you've explained, is intended to provide code that may be used as part of a Java program, and also is designed to function as a standalone application.

To use a class defined in a .java file in another program, it will have to be compiled, but this often need not be a separate build step from building your whole program. Typically, when you build your program, all the .java files in its source code are compiled. Integrated development environments like Eclipse ensures this happens, but you can do this from the command-line as well.

How you'll do it depends on whether or not you're using an automated build system (such as Ant or SCons). If you're not using an automated build system, you can still often build from the command-line with a single invocation of the javac command; the manpage for your javac implementation details how (run man javac). Since this is not the focus of your question, I won't go into any more detail here about how to build a Java application from multiple source code files.

Since any .java source code file will need to be compiled before it can be run, and you want to run Finger as a standalone program, you will have to first compile it:


Then you can run it:

java Finger

That's actually running the file called Finger.class that is created from compiling with javac as detailed above. The java command cannot execute Java source code.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.