LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-13-2006, 03:17 PM   #31
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30

Spoke to soon, I had changed the path but now I am getting this......

Exception in thread "main" Java.Main.NoClassDefFoundError: myfirstprog
 
Old 12-13-2006, 03:23 PM   #32
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
On post #8, you stated that your class is called "HelloWorldApp" right?. In that case, your .java file has to be named HelloWorldApp.java (case-sensitive). If your file is called myfirstprog and your class is called HelloWorldApp, than that could be your problem.
 
Old 12-13-2006, 03:26 PM   #33
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Oops... just read some replies back and it looks like your program is called HelloWorldApp.java. Sorry... still, it is very very weird that the error points to "myfirstprog".
 
Old 12-13-2006, 03:28 PM   #34
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
No, I posted the other app I am trying to get going on another machine, same error message though.
sorry for the confusion.
 
Old 12-13-2006, 03:35 PM   #35
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
I think it will be really hard to spot your problem the way it is: Using two machines without configuring the path correctly and programs with different names for example. I would really recommend you to remove everything you have installed regarding Java from your machine and download a new version. Maybe the one you are trying to use got broken during download (happened to me once). If you are using the packages shipped with Slackware, you will probably be able to see them at /var/log/packages. Remove them...

Once you download a new version of java, configure the path correctly and make sure that you only have one JRE and SDK installed. Remember that SDK also includes the JRE. When you've done that, stick with one machine only. Java can be tricky to install for the first time(in Linux that is...), but once you got that right it will be a blast to install again or in another machine.

Just my two cents

Last edited by Mega Man X; 12-13-2006 at 03:37 PM.
 
Old 12-13-2006, 03:41 PM   #36
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Mega Man X
I think it will be really hard to spot your problem the way it is: Using two machines without configuring the path correctly and programs with different names for example. I would really recommend you to remove everything you have installed regarding Java from your machine and download a new version. Maybe the one you are trying to use got broken during download (happened to me once). If you are using the packages shipped with Slackware, you will probably be able to see them at /var/log/packages. Remove them...

Once you download a new version of java, configure the path correctly and make sure that you only have one JRE and SDK installed. Remember that SDK also includes the JRE. When you've done that, stick with one machine only. Java can be tricky to install for the first time(in Linux that is...), but once you got that right it will be a blast to install again or in another machine.

Just my two cents
What is funny is I had it working on the other machine when i added /home/prog/jdk1.6.0/bin to my path and tried java myfirstprog and it worked, but I ended up screwing up my path and lost all kinds of commands, after I fixed that then It would not work again. The path does work now because when I do javac it creates the class file.

Last edited by M$ISBS; 12-13-2006 at 03:46 PM.
 
Old 12-13-2006, 03:47 PM   #37
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
On the other machine there is no version conflict, When i do which java and javac they are both 1.6.0
 
Old 12-13-2006, 03:58 PM   #38
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Interesting... Well, in the machine without conflict, just make sure that your Java class has the same name as your .java file as I suggested
 
Old 12-13-2006, 04:02 PM   #39
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Just to make sure everything is fine: Copy and paste the following code with your favorite text editor and name it HelloWorldApp.java

Code:
public class HelloWorldApp {

    public static void main(String[] args) {
        System.out.println("Testing");
    }
}
compile with:
javac HelloWorldApp.java

run with:
java HelloWorldApp

If that does not work, I really am not sure what could possibly gone wrong

Last edited by Mega Man X; 12-13-2006 at 04:10 PM.
 
Old 12-13-2006, 04:03 PM   #40
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Mega Man X
Interesting... Well, in the machine without conflict, just make sure that your Java class has the same name as your .java file as I suggested
Whew, I got it. I deleted all the sample java files and the class, downloaded a new one and compiled it and it ran. Thanks for the help, now on to actually learning java, :LOL:
 
Old 12-13-2006, 04:07 PM   #41
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
I've just tested something that could gone wrong... if you try to run your application with .class it will cast that error:

Code:
java HelloWorldApp.class
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp/class
make sure to run without the .class, thus:

java HelloWorldApp
 
Old 12-13-2006, 04:08 PM   #42
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Nice!!! Congratulations M$ISBS ^_^;;

I can recommend some good books about java if you wish
 
Old 12-13-2006, 04:48 PM   #43
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Mega Man X
Nice!!! Congratulations M$ISBS ^_^;;

I can recommend some good books about java if you wish
Sure, That would be cool.
 
Old 12-14-2006, 06:36 AM   #44
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Hi again. Here are my suggestions as promised ^_^;

- The first book is a great book about Java available freely in an electronic format, called Thinking in Java:

http://www.mindview.net/Books/TIJ/

This book will give you some good foundations about Java and, well, it is free .

- One of the first books I bought to learn Java is written by Daniel Liang and I personally still think it is the best book around:

http://cs.armstrong.edu/liang/

The book I have is Introduction to Java Programming, Comprehensive Version, 5E. The sixth edition is out. One thing I've noticed with this book is that it is relatively math-oriented. For example, while most books out there explains what objects are by comparing them to cars or eggs, the author explains Objects through triangles and other geometric figure with some calculations. This is either a good or bad thing depending on you .

- This third book is more like optional. I would not recommend it as the only book to purchase, because it does not go very deeply on any aspects of Java. I see this book more like a complement to the other books with more useful examples and very well written to help you memorize important things and common mistakes a programmer can make in java. It is of course, Head First Java:

http://www.oreilly.com/catalog/hfjava/

Depending which are of java you want to be specialized, like Enterprise or Micro, you will certainly need more specific books.

There is also a thread here at LQ.org with book suggestions for Java that you might want to check out:
http://www.linuxquestions.org/questi...d.php?t=449782

Just let me know if I can help with anything else.

Regards!

Last edited by Mega Man X; 12-14-2006 at 06:37 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java question Jongi SUSE / openSUSE 2 09-19-2005 01:07 PM
Java Question k1ll3r_x Programming 2 08-20-2005 08:10 PM
Java question biojayc Linux - Newbie 8 03-22-2005 03:42 PM
java question zaicheke Programming 5 02-15-2005 12:40 PM
Java Question k1ll3r_x Programming 3 11-13-2004 04:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration