Errors on Run Java Application

Using the Java SDK with TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Robert

Errors on Run Java Application

Post by Robert »

I receive the following error from the DOS prompt when executing a compiled Java program.

*Exception in thread "main" java.lang.NoClassDefFoundError: TextPadTest
Press any key to continue...*

The code I'm trying to run is as follows:

public class TextPadTest{
public static void main(String[] args){
System.out.println("TestPad Test");
}
}
John K

Re: Errors on Run Java Application

Post by John K »

Looks like your parameters are not correct. Are you running Win XP or 2000? Try the following, it should help:

Go to Configure->Preferences->Tools->Run Java Application

You should see a text box labeled "Paramaters", it probably says something like this:
$BaseName

But try changing it to:

-classpath . $BaseName

Also, change the parameters under Configure->Preferences->Tools->Compile Java
to the same thing.

That should clear that error, let me know if it helps.

John
Robert

Re: Errors on Run Java Application

Post by Robert »

I'm on XP, it still doesn't clear the error though thanks for the suggestion :)
xuzhong wang

Re: Errors on Run Java Application

Post by xuzhong wang »

thank John K,you help me solve the problem,but can you tell me what is this which we changed.other how can i add the class which teacher maked and we will use in our homework?
xuzhong wang

Re: Errors on Run Java Application

Post by xuzhong wang »

thank John K,you help me solve the problem,but can you tell me what is this which we changed.other how can i add the class which teacher maked and we will use in our homework?
Anil Kumar

Re: Errors on Run Java Application

Post by Anil Kumar »

Thanks John. It solved my problem.
regards,
Anil.
Teresa

Re: Errors on Run Java Application

Post by Teresa »

I have the exact same error:

*Exception in thread "main" java.lang.NoClassDefFoundError: TextPadTest
Press any key to continue...*


It happens with any program I have, it will compile, but will not run..

Please help!! Did you find a solution to this problem!! Thanks!
erna

Re: Errors on Run Java Application

Post by erna »

i'm on win98 se, i have the error like teresa.i try John k' solution but it doesn't work.
Please help me....
thanks
Christopher Hall

Re: Errors on Run Java Application

Post by Christopher Hall »

You are using the following code:

public class TextPadTest{
public static void main(String[] args){
System.out.println("TestPad Test");
}
}
====================================
Perhaps if you make this modification to the array:

public class TextPadTest{
public static void main(String args[]){
System.out.println("TestPad Test");
}
}

====================================
Did you set the environment variables correctly? Both variables PATH should include your JAVAC.EXE directory (in the JDK \bin directory, I believe). Also, delete the variable CLASSPATH or you will never get reference variables to compile.

Did you try compiling the code? Did you install the JDK on Sun? If you have J++, will that compile there? (Yes, I'm odd; I have J++ and like to switch between TextPad and J++.)

My compiler worked on either of the code segments above, though I have had problems before on compiling with reference variables. After I changed the environment variables, it was fine.
russ

Re: Errors on Run Java Application

Post by russ »

john, I'm somewhat of a novice. I'm on xp and cant get textpad to run my java.
How do i get to configure?


Russ
Graham

Re: Errors on Run Java Application

Post by Graham »

ok, assuming you have the java tools set up in textpad (it's got "compile java" and "run java application" in the tools menu), and you have the java SDK installed (the default directory will be something like C:\j2sdk1.4.1), then you need to do the following things (on xp/2000 anyway).

right-click My Computer, select Properties. Click on the Advanced tab, then the Environment Variables button.

In the System variables section, there is a variable called Path. If you run a program without telling windows exactly where it is, it will look for it in all the directories in the Path. The full path to the "bin" directory of the java sdk must be in here, separated from the others by a semi-colon. Double-click on the Path variable to edit it. If the "Variable value" field is long, it might be easier to copy&paste it into textpad, edit it, then copy&paste it back. Put the path to the bin directory in here. Now it will look something like:
.;C:\WINDOWS;C:\j2sdk1.4.1\bin;....

You also want a variable called Classpath. This does not need to be deleted. This is similar to the Path, but it contains a list of the directories Java will search through to find other classes you might reference in your programs. (Java will automatically look in its own directories for normal classes such as String, so those directories don't need to be in here.) If it doesn't exist, then click the New button and put CLASSPATH as the variable name. If you ever need to reference jar files, you add the full pathname of them (plus the filename) to the end of the classpath, separating each entry by a semi-colon. However, to make things easy, the first directory Java searches should be the current directory (where the class file you're trying to run will be), which is referenced by a '.'. So the classpath will be:
.;.....

You can also give java a new classpath every time you run it with the -classpath option as John K showed above, but it's easier to put the current directory (.) permanently in the classpath.
hope this helps.
Graham

Re: Errors on Run Java Application

Post by Graham »

By the way, if you change the path or classpath (or any environment variables) when textpad is open, you'll have to exit it and open it again, to enable it to read the new path/classpath/whatever.
John K

Re: Errors on Run Java Application

Post by John K »

I only had to enter it one time. That setting doesnt change until I go back to the preferences and change it there. Yours changes? That shouldn't happen...
Post Reply