Netbeans and Eclipse ok, Textpad not...

Using the Java SDK with TextPad

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

Post Reply
Random
Posts: 6
Joined: Sun Mar 23, 2008 5:14 pm

Netbeans and Eclipse ok, Textpad not...

Post by Random »

Hi, I made a little Java program with Netbeans, and it works with no problem.
When trying to compile it with Eclipse I had to move some files(don't remember now) to make it work, otherwise Eclipse give me some errors.
So this is my problem: when trying to compile the program with Textpad it gives me some errors ( cannot find xx, cannot find xxx ...) and the program won't start. I tried to use the same method used with Eclipse, but I didn't succeed.

So, do you know if Netbeans writes some code parts in another file, or something else? Is it a known problem? Can you help me to make the program running also with Textpad?

If necessary I can send you my source files.

Thanks, bye
agnul
Posts: 21
Joined: Tue Feb 10, 2004 9:42 am
Location: Italy

Post by agnul »

Both Eclipse and Netbeans are IDEs and they're main job is compiling java code. Both use their own compiler and know where to look for class libraries, without the need for you to tell them.

Textpad on the other hand is only a text editor and relies on an external tool (the javac compiler) to compile java code. You need to tell the compiler where to look for java classes, unless they can be found in the default places.

All the gory details can be found here and here. An brief tutorial on how to start writing java programs is here.

If you're starting with java it would be a good idea to first familiarize with the command line tools and only after that start using an IDE.
Random
Posts: 6
Joined: Sun Mar 23, 2008 5:14 pm

Post by Random »

Thanks agnul, I followed your instructions and read the documentation, but it still gives me errors.
All my .java files are in this path:
C:\Eclipse Workspace\proj\src\test

So I used this command in cmd.exe:
javac -classpath C:\Eclipse Workspace\proj\src\test *.java

The command line noticed me some warnings for deprecated APIs, but I think this isn't the problem, right?

Then in command line I wrote:
java Autonoleggio (<-- this is the main java file)

But it gives the errors you see in this image:
Image

So, how do I solve it?

Then, it generates a lot of .class files for the same java file(Autonoleggio.class, Autonoleggio$1.class, ... , Autonoleggio$11.class) . Is it normal?
agnul
Posts: 21
Joined: Tue Feb 10, 2004 9:42 am
Location: Italy

Post by agnul »

Looking at your screenshot a couple of things come to mind

:arrow: if all the classes and libraries are in your current working dir you don't need to specify a -classpath option (unless you changed the default classpath)

:arrow: if you specify the -classpath option it should always include the current working directory, so add ".;" at the beginning

:arrow: if you give the -classpath option to javac you should give the same option to java

:arrow: as for your error... the error message says "wrong name", and the screenshot suggests Autonoleggio is inside the "test" package, so your classpath should point to ".....\src", and you should run the class doing something like "java test.Autonoleggio".

The Autonoleggio$1..11 class files are generated for the anonymous inner classes you have in Autonoleggio.java
Random
Posts: 6
Joined: Sun Mar 23, 2008 5:14 pm

Post by Random »

I followed your suggestions.Now new errors:
Image

Would you like me to link here my source files?
agnul
Posts: 21
Joined: Tue Feb 10, 2004 9:42 am
Location: Italy

Post by agnul »

I followed your suggestions.Now new errors...
No, you didn't.

javac is the compiler. You pass file names as arguments to the compiler, and those filenames should have the .java extension.

java is the interpreter. You pass class names as arguments to the interpreter. Class names don't have any extension.

The interpreter is telling you that it cannot find a class named "java" inside the package "Autonoleggio", and it's telling you that because you gave it a file name instead of a class name. Why should the interpreter look for a class named "java" inside a package named "Autonoleggio"? Because in class names "." is used as the package separator.

What I tould you instead is that your "Autonoleggio" class probably lives in the "test" package, so the interpreter expects the class name to be test.Autonoleggio

Go back to my first answer, re-read all the links and then read the tutorial lesson on packages also. Then read all of them again.
Random
Posts: 6
Joined: Sun Mar 23, 2008 5:14 pm

Post by Random »

I did it! (... I should say YOU did it)
Following your suggestions, this time correctly, it runs perfectly!

THANK YOU very much for your support and your big patience!!
:D

Best regards
Post Reply