File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Trouble when I execute my archive .class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trouble when I execute my archive .class" Watch "Trouble when I execute my archive .class" New topic
Author

Trouble when I execute my archive .class

Arthur Braga
Greenhorn

Joined: Mar 06, 2010
Posts: 9
People, I have a problem! (Great discovery!!! All of us have troubles!) and I come on from Brazil to ask you about my case!

If my english will be horrible, don't fear, because it can be worse! hehe

So...Let's go!
I'm a beginner in Java and I was made the famous "Hello World!"...
However, when I compile my .java it worked, but after this, when I run it, appeared to me this error:

"Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstApp/class
Caused by: java.lang.ClassNotFoundException: MyFirstApp.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: MyFirstApp.class. Program will exit."


Attached this you will find a printscreen of error!

I tried search in internet about this, but I had no success! YOU ARE MY LAST HOPE!!! HELP-ME GUYS! .



[Thumbnail for Erro_Compilação-Execução_Java.png]



Arthur Lisbôa de Braga
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
Welcome to the Ranch

We are your first hope

You should write java C:\...MyFirstApp

Not java C:\...MyFirstApp.class

Miss out the extension.
Arthur Braga
Greenhorn

Joined: Mar 06, 2010
Posts: 9
Thanks for the reception Campbell!

The extension isn't the problem! I test this too! Same error! Other reason for this hapening

But Thanks for the sugest Ritchie!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18707
    
  40

Arthur Braga wrote:The extension isn't the problem! I test this too! Same error! Other reason for this hapening

But Thanks for the sugest Ritchie!



Well, based on the picture you uploaded, the extension is clearly the problem. You have to give the qualified named of the class, not the name of the class file.


If you get "other reason" when you don't use the filename, then you need to tell us what the exception is. We can't guess at the JVM exception being thrown.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Arthur Braga
Greenhorn

Joined: Mar 06, 2010
Posts: 9
In attachment, other image without .class after the name of the class!

THIS IS ALL the content of class file! I think it strange, because I thought it was larger than this:
-----------------------------------------------------------------------------------------------
Êþº¾


SourceFile
MyFirstApp
-----------------------------------------------------------------------------------------------
Tell to me if the code are complete!? I repeat...this is ALL the content, neither more nor less!


[Thumbnail for Erro_Compilação-Execução_Java_SEM_CLASS.png]

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18707
    
  40


As mentioned, the parameter is the fully qualified name of the class -- not the name of the file, or the directory that the file is in. The drive letter and directory is not part of the class name.

Henry
Arthur Braga
Greenhorn

Joined: Mar 06, 2010
Posts: 9
Yeah! I understand what you said!

You mean to replace: "%java C:\JAVA\MyFirstApp.class" to "%java MyFirstApp"! Yes or No?!

If yes I test with this parameters but don't worked again!
If no, give me samples of you mean?

Thank you very much for the help!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18707
    
  40


With absolutely no details, we can't help you. This is likely a config error, so we need to know your configs.... specifically... your PATH, your CLASSPATH, your directory structure, how are you compiling (including directory location), and how are you running (including directory location). And of course, all error messages for all of this.

And if possible, can you cut-n-paste the text -- graphics are annoying to read, and eat up bandwidth.

Henry
Arthur Braga
Greenhorn

Joined: Mar 06, 2010
Posts: 9
OK! Let's begin the end of this case!

BEFORE I JOIN IN JAVARANCH AND POST MY ASK HERE!
----------------------------------------------------------------------------------
I downloaded the jdk-6u18-windows-i586 (version 6-update 18 of JDK for windows) and installed it;
After this I began read a book for Java's starter called in brazilian "USANDO A CABEÇA! JAVA" (maybe you recognize as "HEAD FIRST JAVA" from Kathy Sierra & Bert Bates) and I tried made the Hello World sampled in the book!
I did the code in a simple text editor, more specifically, in Context;
I declared in the ambience variables a new variable called PATH and I put as value the directory BIN of JDK main local.
So PATH = (C:\Program Files (x86)\Java\jdk1.6.0_18\bin) BUT I don't create none CLASSPATH
Then I entered in CMD=COMMAND=EMULATION OF DOS and I compiled my code with: javac C:\JAVA\MyFirstApp.java (THIS DIRECTORY I PUT MY CODES)
Worked the compilation, but when I tried execute with this code: java C:\JAVA\MyFirstApp (as Henry said-without extension) appear the error (ATTACHED HERE!)
----------------------------------------------------------------------------------

Well, this is how all happened!
Can I help you with this explanation?

Thanks for antention!



[Thumbnail for Erro_Compilação-Execução_Java_SEM_CLASS.png]

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18707
    
  40

Arthur Braga wrote:
You mean to replace: "%java C:\JAVA\MyFirstApp.class" to "%java MyFirstApp"! Yes or No?!

If yes I test with this parameters but don't worked again!


Yes. This is exactly what I mean. And as before... I have no info on "don't worked again", so can't help.

Henry
Arthur Braga
Greenhorn

Joined: Mar 06, 2010
Posts: 9
OK...I test how you said and attached I put the error without the directory and .class!

I put also, the code of MyFirstApp.java for you see and tell me if you can help me or not!

Thanks!


[Thumbnail for QUESTÃO.png]

[Thumbnail for CODE.png]

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18707
    
  40



cd c:\JAVA

javac MyFirstApp.java

java MyFirstApp
Arthur Braga
Greenhorn

Joined: Mar 06, 2010
Posts: 9
OOOOHHHH MANNN!!! THANK YOU VERY MUCH!!!

WORKED!!!

Thanks Henry, but why my mode was incorrect? the compiler not recognize the directory as parameter?!
So, Thanks for atention my friend! If you have MSN, can you post here?

THANKS ALL FOR ATENTION AND FOR HELP ME!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18707
    
  40


The compiler takes a file, so in this very simple case, it was possible to figure out the location. The JVM does not, hence, it was not able to find the class files. That is what the classpath is for, which you are not using.

Basically, you need to either (1) setup a classpath or (2) be in the right location to compile and run.

Henry
Arthur Braga
Greenhorn

Joined: Mar 06, 2010
Posts: 9
Thank you for the explanation!

Now I understand the CLASSPATH's function because I created one more variable for CLASSPATH and worked without I put the correct location in CMD!

Again, Thanks for all!

public static void main(String[] args){
System.out.print("CASE RESOLVED");
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble when I execute my archive .class