• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Trouble when I execute my archive .class

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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! .
Erro_Compila-o-Execu-o_Java.png
[Thumbnail for Erro_Compila-o-Execu-o_Java.png]
ERROR_COMPILE/EXECUTE_JAVA
 
Marshal
Posts: 79938
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Arthur Braga
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
Erro_Compila-o-Execu-o_Java_SEM_CLASS.png
[Thumbnail for Erro_Compila-o-Execu-o_Java_SEM_CLASS.png]
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

Erro_Compila-o-Execu-o_Java_SEM_CLASS.png
[Thumbnail for Erro_Compila-o-Execu-o_Java_SEM_CLASS.png]
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
QUEST-O.png
[Thumbnail for QUEST-O.png]
CODE.png
[Thumbnail for CODE.png]
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


cd c:\JAVA

javac MyFirstApp.java

java MyFirstApp
 
Arthur Braga
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");
}
 
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic