Java Compile Error

Using the Java SDK with TextPad

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

Post Reply
Alan

Java Compile Error

Post by Alan »

Hi there,
Im new to java and im trying to compile a .java file called MyFirstApplication.java I know it should compile as i have compiled it on the uni's server computers.

the program is:

import javabook.*;

class MyFirstApplication
{
public static void main (String args[])
{
MainWindow mainWindow;
mainWindow = new MainWindow( ); //create and
mainWindow.show(); //display a window
}

}

However when i try to compile i get this error:

C:\COA256\Sample_Programs\Ch2\MyFirstApplication.java:12: Superclass java.lang.Object of class MyFirstApplication not found.
class MyFirstApplication
^
1 error

Tool completed with exit code 1

I have the compiler's parameters set to. -classpath .;c:\coa256\ $File
which is where my javabook is. But it still does not compile.

If it helps i am running XP Pro.

I would be verry greatfull if anyone could help me out.
Cheers.
Guest

Post by Guest »

Think you need to add public in before class................
Garrett

Looks like your JDK is messed up.

Post by Garrett »

The fact that your java install is messed up. The fact that javac.exe can't find java.lang.Object means SOMETHING is fubarred. You should uninstall and reinstall the JDK. I don't know exactly what you're talking about with this:

-classpath .;c:\coa256\ $File

stuff, but if you explicitly declare the classpath, you should know that it overrides the CLASSPATH system variable. That's why you should actually either modify your CLASSPATH system variable, or you should designate classpath like this:

-classpath %CLASSPATH%;.;c:\coa256\ $File

That way, you don't lose anything you already had. Though I still don't understand how you'd lose java.lang.Object. Perhaps if you're going to declare the classpath explicitly, you'll also need to explicitly include the core classes, such as rt.jar, tools.jar, etc...

I'd need more information to more accurately diagnose what's going on here. For example, what happens if you don't declare the -classpath variable when you compile, and why you need to in the first place. What is your directory structure? Where is the javabook package located in your directory tree?
Alan

Post by Alan »

Thanx for helping me out Garrett,

I tried uninstalling the JDK and reinstalling, still got the same reply when compiling.
If i do not declare the parameters in Prefrences --> compile Java, and leave it as $file i get this message when trying to compile:

C:\COA256\Sample_Programs\Ch2\MyFirstApplication.java:10: Package javabook not found in import.
import javabook.*;
^
1 error

Tool completed with exit code 1

I also try changeing the parameters to:
-classpath %CLASSPATH%;.;c:\coa256\ $File
However i still got the same reply as before.

My Javabook is located in:
C:\coa256\Javabook

and the java file im trying to compile is in:
C:\COA256\Sample_Programs\Ch2

I also tried uninstalling and reinstalling the Java 2 Runtime Enviroment.
but still no difference.

I hope this is of more help.

I didn't quite understand what you ment by explicitly include the core classes.
How would i go about doing that.

Thanx a lot for all you help.
Garrett

Ah! You need to be case-sensitive

Post by Garrett »

Here's your problem:

You class imports the package:

import javabook.*;

But your directory structure doesn't have the "javabook" package. It has the "Javabook" package. You must remember that java is case-sensitive, even if Windows is not. Your package structure is not correct. Make sure that your directories are accurately named.

Now, we appear to have lost that other problem, the one where java loses java.lang.Object. I'm not precisely sure how, but perhaps reinstalling remedied the issue.

As for the locations of your directories, you should try putting all you packages in the same directory structure. Such as like this:

\source
\javabook
\someclass.class
\someotherclass.class
\sample
\MyFirstApplication.class

That way, you needn't make explicit declaration of the classpath, provided that your %CLASSPATH% variable includes the current directory, ie:

;.;

You should only try that if you've already corrected the directory names, (assuming the typo is in your directories, not just your post,) and it still doesn't help.
Garrett

Post by Garrett »

Correction to the directory structure I posted before:

This system strips leading and trainling spaces, rendering the info I just gave you about the directory structure misleading. Here it is again:

\source
\source\javabook
\source\javabook\ClassOne.class
\source\javabook\ClassTwo.class
\source\sample
\source\sample\MyFirstApplication.class

This assumes, of course, that your source files and class files share the same directories. If not, you can't do this.
Alan

Post by Alan »

Thanx for all your help!

i managed to fix the problem in the end, i uninstalled everything. the jdk the java runtime enviroment and textpad.

i then installed the jdk 1.2, which has the run time enviroment included. then installed textpad.

i then reorganised my directory structure and set the classpath so that it was pointing at my javabook, and it worked.

thanx again for all your help.
And if anyone else is having the some prob i hope this helps then too.

Cheers,
Alan
Post Reply