Showing posts with label java. Show all posts

The classpath problem  

Posted by shashank in

July 8, 2009
The same image can be seen in detail at:


When I instruct to compile the program into the adat folder, the class files are created. From being anywhere in the directory - true at least for the cases I have tried yet - I can execute the program with the instruction:
>java -cp C:\jtemp\adat MyPack.AccountBalance

But when I go to the actual location the following command fails to execute:
C:\jtemp\adat>java MyPack.AccountBalance

and yields a "NoClassDefFoundError".

The conclusion I have derived from this is that the "classpath" variable is locked by default and hence the programs don't execute unless the same is explicitly changed. Perhaps such a conclusion is wrong, but at present it enables me to execute the simple programs I am writing.

How I solved the preceding problem  

Posted by shashank in

Wednesday, May 27, 2009
Source (logging in necessary): http://www.daniweb.com/forums/thread193778.html
"Thanks a lot to all!

@sos and @adatapost
Sorry for not being able to heed to your(sos) first comment. The concept of package is yet unclear to me. As you advised I tried to create a new folder and in that folder I created created a new file name j2.java
I removed the package code line and save the rest of the code as it was in the previous example after changing the class name to j2.
Then I used the following commands:
javac j2.java -d . //as recommended by adatapost
java -classpath . j2

After that the output was
Hello World!

This was my first step in learning Java. I will try to study Java further and the concept of package. Will post a new problem if I have any with regards to package.

Thank You once again.

Regards,

-sgsawant"

Started with Java Programming....  

Posted by shashank in


Monday, May 25, 2009
Today (actually Yesterday considering it is 0236hrs in the morning) I started with Java programming. Downloaded the ebooks Complete Reference Java by Herbert Schildt and Java for dummies from esnips.com
Also downloaded the bundle of JDK and Netbeans from Sun's official site.

After fiddling with netbeans for some time I ventured into the command prompt method of operating Java. After a lot of headache and changing variables in Control Panel>System>Advanced>System Variable I was able to correctly execute "javac HelloWorldApp.java" command, which worked fine.
But I could not execute "java HelloWorldApp" command which kept on returning the error:
Exception in thread "main" java.lang.noclassdef
..
..

So to see whether this was a universal problem I tried downloading the CMUcamGUI files which were bundled with the CMUCAM I used for my robot Ouimet.
Even that thing did not execute for a while when I tried "java CMUcamGUI" (the class file was already there; so no need of javac command).
Finally I tried the command "java -classpath . CMUcamGUI" which asks the compiler to look for the class file in the current directory. That solved the problem for CMUcamGUI but the problem for HelloWorldApp still persists.

Moral of the story: Remember the following command (though it has not entirely solved the above problem)
java -classpath . CMUcamGUI