LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 08-28-2004, 12:50 AM   #1
nro
Member
 
Registered: Oct 2003
Distribution: Mandrake 9
Posts: 46

Rep: Reputation: 15
Problem executing java programs


I have been searching all over the net for the past few hours trying to find a solution to this horrible problem.
I have a simple program:

Code:
class Test {
  int number=0;
  
  public static void main(String args[]) {
    Test t = new Test();
    System.out.println(t.number);
  }
}
Here was my first method of compilation/execution:
I simply used the Java SDK.

[mike@localhost Java]$ javac test.java
[mike@localhost Java]$ java test
Exception in thread "main" java.lang.NoClassDefFoundError: test

There is the problem: "Exception in thread "main" java.lang.NoClassDefFoundError: test"

I am able to successfully compile the java file, but when it comes to executing it, it gives me trouble. I have tried other simple programs(such as the basic HelloWorld) and they all give me the same trouble.

My second method of compilation/execution:
I downloaded NetBeans IDE 3.6.

I created a project file and used the same code from above. The compilation went smooth, but once again, I got that error.

I have read in other places that I'm missing the classpath, but I'm unsure which .jar file I should be looking for.

Any help is always appreciated.

Thanks,
Mike
 
Old 08-28-2004, 01:06 AM   #2
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
You are using "test.java" as file name and "Test" as the class name (note that Java is case sensitive). So you have to use the same main class as the name of the source file....
 
Old 08-28-2004, 01:09 AM   #3
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Here is my:

Code:
// test.java

class test {
    int number=1;

    public static void main(String[] args) {
        test t = new test();
        System.out.println(t.number);
    }
}
 
  


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 code executing SQL statements problem randomx Programming 1 11-09-2004 10:59 AM
Problem executing this piped command: JAVA randomx Programming 1 07-16-2004 07:39 PM
executing programs?!? cmargiol Linux - General 8 10-29-2003 02:38 PM
Executing X-Programs remotely frankieboy Linux - General 3 10-08-2003 02:31 AM
executing programs with arguments ? shaneblyth Mandriva 10 09-27-2003 08:01 PM

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

All times are GMT -5. The time now is 03:48 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