problem with compiling....

Have a java file which has a public and a non-public top level classes.

Here is the file named MainClass.java

public class MainClass

{

//....blah...blah..

}

/*Note: This is not public.*/

class AnotherClassInSameFile

{

//....blah...blah..

}

AnotherClassInSameFile is being used by classes outside the file as well (same package ofcourse)

When I try to compile MainClass.java using JBuilder3 with jdk1.2.2 it works fine.(We have been doing this for past two years) Now we are trying to compile the same from command prompt using javac (the same jdk1.2.2) and we get the following error.

d:\src\mypackage\MainClass.java: class mypackage\AnotherClassInSameFile is defined in MainClass.java. Because it is used outside of its source file, it should be defined in a file called "AnotherClassInSameFile.java".

Since we cannot write the non public top level class in another file, can you please suggest a way around? / explain why this is not working in javac but was working in JBuilder3 ?

[1075 byte] By [catchknsa] at [2007-9-27 8:28:06]
# 1

If 'AnotherClassInSameFile' is not an inner class to your MainClass, then it is better to create it in a sepereate file called 'AnotherClassInSameFile.java'.

I didn't get you properly about 'can't create non public top level class in another file', why? You can create a class which is not a public. Then it will take default 'package'.

Sudha

sudha_mpa at 2007-7-8 16:28:45 > top of Java-index,Developer Tools,Java Compiler...
# 2

Hi,

When I said "we cannot write the non public top level class in another file", I didn't mean that Java is restricting us. But was rather trying to say that since our project is huge with lots of dependencies set in, now its not feasible (desirable :-) to go and write that class in another file.

We are basically trying to figure out why the stuff works with JBuilder3 but not from command prompt. Moreover we are also on the look out for a work around which would save us from writing many classes like "AnotherClassInSameFile" in seperate files.

Thanks for your interest.

Karthik

catchknsa at 2007-7-8 16:28:45 > top of Java-index,Developer Tools,Java Compiler...
# 3
did u use forward slashes while compiling? if so then this problem could arise. else try deleting all the old class files and recompile ...
ladyreda at 2007-7-8 16:28:45 > top of Java-index,Developer Tools,Java Compiler...
# 4
Class within a class. Sounds like inner classes. Just recompile the source code in the java version you are using. Then, deal with the bugs as they come.
kuyalfinatora at 2007-7-8 16:28:45 > top of Java-index,Developer Tools,Java Compiler...