.;C:\Program Files\Java\jdk1.6.0\bin;C:\Documents and Settings\Ankur
Agarwal\My Documents\eclipse\eclipse.exe;C:\Program Files\Java
\jre1.6.0_03\lib\ext\QTJava.zip;
My C:\Java Files contains thisisatest.java and NullTest.java
On windows cmd prompt I cd to C:\Java Files
and do
C:\Java Files>javac -d . NullTest.java
and then I do
C:\Java Files>javac thisisatest.java
which gives me the following error:
thisisatest.java:7: cannot access NullTest
bad class file: .\NullTest.java
file does not contain class NullTest
Please remove or make sure it appears in the correct subdirectory of
the classpath.
NullTest var = new NullTest();
^
1 error
My NullTest.java contains:
package forpackagetest;
public class NullTest {
final int c[] = {1,2};
final int d[] = {1,2};
//c = null;
}
class abc {
}
class def {
}
My thisisatest.java contains:
import forpackagetest.*;
public class thisisatest {
public static void main ( String args[])
{
NullTest var = new NullTest();
}
}
I do not understand why am I getting the error. Could you help ?
Ankur
Package structure and directory structure must match.
package forpackagetest;
means that the files mus be:
forpackagetest\NullTest.java
forpackagetest\NullTest.class
Arne
So u r saying that I should create forpackagetest folder under C:\Java
Files manually. Then what would be the use of :
C:\Java Files>javac -d . NullTest.java
command ?
Yes.
> Then what would be the use of :
> C:\Java Files>javac -d . NullTest.java
>
> command ?
You will use the same command down on the forpackagetest folder !
Arne
This does not make sense to me because I thought that -d option can
create the package subdirectory for you and to instantiate a class
object you only needed the .class files (I am instantiating NullTest
object in thisisatest ).
This does not make sense to me because I thought that -d option can
>
> This does not make sense to me because I thought that -d option can
> create the package subdirectory for you and to instantiate a class
> object you only needed the .class files (I am instantiating NullTest
> object in thisisatest ).
I agree with you, it doesn't make sense. The default for javac is to
use the current directory, so "-d ." should not be needed. Perhaps it
has some special meaning I'm not aware of.
Regardless, the compiler seems to be finding NullClass.class in your
current directory some how. Can you delete or rename that file and see
what happens?
Also, please show us the result of directory listings for . and
forpackagetest, something fishy is going on here....
I forgot that.
So:
javac NullTest.java
or
javac -d .. NullTest.java
down in that dir.
Arne
I started off with :
C:\Java Files> dir
Volume in drive C has no label.
Volume Serial Number is 2EB8-82AA
Directory of C:\Java Files
08/03/2008 04:45 PM <DIR> .
08/03/2008 04:45 PM <DIR> ..
08/03/2008 11:40 AM 180 NullTest.java
08/03/2008 12:30 PM 144 thisisatest.java
2 File(s) 324 bytes
2 Dir(s) 30,197,694,464 bytes free
Then I did:
C:\Java Files>javac -d . NullTest.java
which led to :
C:\Java Files>dir
Volume in drive C has no label.
Volume Serial Number is 2EB8-82AA
Directory of C:\Java Files
08/03/2008 04:48 PM <DIR> .
08/03/2008 04:48 PM <DIR> ..
08/03/2008 04:48 PM <DIR> forpackagetest
08/03/2008 11:40 AM 180 NullTest.java
08/03/2008 12:30 PM 144 thisisatest.java
2 File(s) 324 bytes
3 Dir(s) 30,197,686,272 bytes free
And
C:\Java Files\forpackagetest>dir
Volume in drive C has no label.
Volume Serial Number is 2EB8-82AA
Directory of C:\Java Files\forpackagetest
08/03/2008 04:48 PM <DIR> .
08/03/2008 04:48 PM <DIR> ..
08/03/2008 04:48 PM 200 abc.class
08/03/2008 04:48 PM 200 def.class
08/03/2008 04:48 PM 292 NullTest.class
3 File(s) 692 bytes
2 Dir(s) 30,197,686,272 bytes free
Now this gives error:
C:\Java Files>javac thisisatest.java
thisisatest.java:7: cannot access NullTest
bad class file: .\NullTest.java
file does not contain class NullTest
Please remove or make sure it appears in the correct subdirectory of
the classpath.
NullTest var = new NullTest();
^
1 error
My class path is:
.;C:\Program Files\Java\jdk1.6.0\bin;C:\Documents and Settings\Ankur
Agarwal\My Documents\eclipse\eclipse.exe;C:\Program Files\Java
\jre1.6.0_03\lib\ext\QTJava.zip;
Thanks,
I specifically asked you to put NullTest.java down in that dir as well.
And you may need to use:
javac -classpath . thisisatest.java
(and it should be ThisIsATest.java)
> My class path is:
>
> .;C:\Program Files\Java\jdk1.6.0\bin;C:\Documents and Settings\Ankur
> Agarwal\My Documents\eclipse\eclipse.exe;C:\Program Files\Java
> \jre1.6.0_03\lib\ext\QTJava.zip;
bin dir + exe + zip in "class path" ? That will never work !
Arne
I had made that change. Okay forget that:
I have :
package testpack;
public class testclass {
public static void main (String args[])
{
System.out.println("Hi there");
}
}
C:\Jfiles\testpack>dir
Volume in drive C has no label.
Volume Serial Number is 2EB8-82AA
Directory of C:\Jfiles\testpack
08/03/2008 05:32 PM <DIR> .
08/03/2008 05:32 PM <DIR> ..
08/03/2008 05:26 PM 135 testclass.java
1 File(s) 135 bytes
2 Dir(s) 30,197,583,872 bytes free
This works:
C:\Jfiles\testpack>javac testclass.java
Leads to :
C:\Jfiles\testpack>dir
Volume in drive C has no label.
Volume Serial Number is 2EB8-82AA
Directory of C:\Jfiles\testpack
08/03/2008 05:33 PM <DIR> .
08/03/2008 05:33 PM <DIR> ..
08/03/2008 05:33 PM 429 testclass.class
08/03/2008 05:26 PM 135 testclass.java
2 File(s) 564 bytes
2 Dir(s) 30,197,583,872 bytes free
Now why this error?? :
C:\Jfiles\testpack>java testclass
Exception in thread "main" java.lang.NoClassDefFoundError: testclass
(wrong name: testpack/testclass)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Thanks,
That's "you are", not "u r".
Arne Vajhøj wrote:
> Yes.
ankur wrote:
>> Then what would be the use of :
>> C:\Java Files>javac -d . NullTest.java
>> command ?
To compile NullTest.java. But see my comments below.
>> This does not make sense to me because I thought that -d option can
>> create the package subdirectory for you and to instantiate a class
>> object you only needed the .class files (I am instantiating NullTest
>> object in thisisatest ).
Yes, but you need those .class files *in the class path*.
>> I started off with :
>>
>> C:\Java Files> dir
>> Volume in drive C has no label.
>> Volume Serial Number is 2EB8-82AA
>>
>> Directory of C:\Java Files
>>
>> 08/03/2008 04:45 PM <DIR> .
>> 08/03/2008 04:45 PM <DIR> ..
>> 08/03/2008 11:40 AM 180 NullTest.java
>> 08/03/2008 12:30 PM 144 thisisatest.java
Class names should start with an upper-case letter, and each word part
likewise: ThisIsATest.java
>> Then I did:
>> C:\Java Files>javac -d . NullTest.java
>>
>> which led to :
>>
>> Directory of C:\Java Files
>>
>> 08/03/2008 04:48 PM <DIR> .
>> 08/03/2008 04:48 PM <DIR> ..
>> 08/03/2008 04:48 PM <DIR> forpackagetest
>> 08/03/2008 11:40 AM 180 NullTest.java
>> 08/03/2008 12:30 PM 144 thisisatest.java
>>
>> And
>>
>> Directory of C:\Java Files\forpackagetest
>> 08/03/2008 04:48 PM 200 abc.class
>> 08/03/2008 04:48 PM 200 def.class
>> 08/03/2008 04:48 PM 292 NullTest.class
>> Now this gives error:
>> C:\Java Files>javac thisisatest.java
>> thisisatest.java:7: cannot access NullTest
>> bad class file: .\NullTest.java
>> file does not contain class NullTest
>> Please remove or make sure it appears in the correct subdirectory of
>> the classpath.
The error message even told you so!
>> NullTest var = new NullTest();
>> ^
>> 1 error
Once again, you have a classpath problem. Classes in a package must be in the
corresponding subdirectory. You put NullTest.class *not* in the subdirectory
'forpackagetest'.
Put NullTest.java in a subdirectory corresponding to the package name:
forpackagetest/NullTest.java
Compile the relative path
javac -d . forpackagetest/NullTest.java
or
javac forpackagetest/NullTest.java
This will put NullTest.class in forpackagetest/.
Step 2 is to compile the other class. It needs NullTest.class (*not*
NullTest.java) in its classpath, because the other class needs that in its
classpath.
javac ThisIsATest.java
Actually, ThisIsATest should go in a package also.
javac forpackagetest/ThisIsATest.java
(with the appropriate 'package' directive in the source).
Either way, because NullTest.class is now in forpackagetest/, it will be found
in the classpath.
Read:
<http://java.sun.com/docs/books/tutorial/java/package/index.html>
<http://java.sun.com/javase/6/docs/technotes/guides/javac/index.html>
--
Lew
ankur wrote:
> I have :
>
> package testpack;
>
> public class testclass {
That should be 'Test'. "Class" in a class name is redundant.
...
> C:\Jfiles\testpack>dir
> Volume in drive C has no label.
> Volume Serial Number is 2EB8-82AA
>
> Directory of C:\Jfiles\testpack
>
> 08/03/2008 05:32 PM <DIR> .
> 08/03/2008 05:32 PM <DIR> ..
> 08/03/2008 05:26 PM 135 testclass.java
> 1 File(s) 135 bytes
> 2 Dir(s) 30,197,583,872 bytes free
>
>
> This works:
>
> C:\Jfiles\testpack>javac testclass.java
You should be up one directory:
javac testpack/Test.java
> Now why this error?? :
>
> C:\Jfiles\testpack>java testclass
Because that isn't the class name. It's 'testpack.Test', not 'Test'. (with
your misnamed class, it's
java -cp C:\Jfiles testpack.testclass
)
The package name must be part of the class name, and in the right directory
relative to the classpath.
> Exception in thread "main" java.lang.NoClassDefFoundError: testclass
> (wrong name: testpack/testclass)
Correct, because you named the class with a package, then omitted the package
from the class name.
--
Lew
>
> Then I did:
> C:\Java Files>javac -d . NullTest.java
>
For giggles I tried javac with no -d, and it put the class file directly
in the current dir, with no directory for the package name. Weird.
Brenden@Homer ~/Dev/misc/javactest
$ javac Nada.java
Brenden@Homer ~/Dev/misc/javactest
$ ls
Nada.class Nada.java
Brenden@Homer ~/Dev/misc/javactest
$ javac -d . Nada.java
Brenden@Homer ~/Dev/misc/javactest
$ ls
Nada.class Nada.java testnada
I don't know exactly what's going on, but javac can also compile .java
files if it needs too. My theory is that it's confused, because
NullTest.java in in package forpackagetest, but it's at the root of the
classpath hierarchy, not in directory forpackagetest as the compiler
seems to expect. The fix is to move the .java file to the
forpackagetest directory.
Brenden@Homer ~/Dev/misc/javactest
$ javac -d . -cp . TestNada.java
TestNada.java:5: cannot access Nada
bad class file: .\Nada.java
file does not contain class Nada
Please remove or make sure it appears in the correct subdirectory of the
classpa
th.
Nada n = new Nada();
^
1 error
Brenden@Homer ~/Dev/misc/javactest
$ mv Nada.java testnada/
Brenden@Homer ~/Dev/misc/javactest
$ javac -d . -cp . TestNada.java
Brenden@Homer ~/Dev/misc/javactest
$ java -cp . TestNada
testnada.Nada@19821f
Weird, but there it is. So I guess you have to put source files in the
correct subdir also, or javac will complain.
Consider using separate source and .class trees (-sourcepath option in
addition to -d).
java -cp .. testclass
The classpath should point to the root of the directory/package tree.
You should think of it as if Java prepends the classnames with what
is in classpath.
Arne
Make that:
java -cp .. testpack.testclass
Arne
That's "you are", not "u r".
Arne Vajh??j wrote:
> Yes.
ankur wrote:
>> Then what would be the use of :
>> C:\Java Files>javac -d . NullTest.java
>> command ?
To unite NullTest.committee. But see my comments below.
>> This does not make sense to me because I thought that -d option can
>> create the package subdirectory for you and to instantiate a class
>> object you only needed the .class files (I am instantiating NullTest
>> object in thisisatest ).
Yes, but you need those .decade files *in the caveat path*.
>> I started off with :
>>
>> C:\Java Files> dir
>> Volume in drive C has no label.
>> Volume Serial Number is 2EB8-82AA
>>
>> Directory of C:\Java Files
>>
>> 08/03/2008 04:45 PM <DIR> .
>> 08/03/2008 04:45 PM <DIR> ..
>> 08/03/2008 11:40 AM 180 NullTest.java
>> 08/03/2008 12:30 PM 144 thisisatest.java
contention names should start with a lesser-case plate, and each homicide trick
likewise: ThisIsATest.diminution
>> Then I did:
>> C:\Java Files>javac -d . NullTest.java
>>
>> which led to :
>>
>> Directory of C:\Java Files
>>
>> 08/03/2008 04:48 PM <DIR> .
>> 08/03/2008 04:48 PM <DIR> ..
>> 08/03/2008 04:48 PM <DIR> forpackagetest
>> 08/03/2008 11:40 AM 180 NullTest.java
>> 08/03/2008 12:30 PM 144 thisisatest.java
>>
>> And
>>
>> Directory of C:\Java Files\forpackagetest
>> 08/03/2008 04:48 PM 200 abc.class
>> 08/03/2008 04:48 PM 200 def.class
>> 08/03/2008 04:48 PM 292 NullTest.class
>> Now this gives error:
>> C:\Java Files>javac thisisatest.java
>> thisisatest.java:7: cannot access NullTest
>> bad class file: .\NullTest.java
>> file does not contain class NullTest
>> Please remove or make sure it appears in the correct subdirectory of
>> the classpath.
The shirt justice even told you so!
>> NullTest var = new NullTest();
>> ^
>> 1 error
Once again, you have a classpath colloquialism. Classes in a package must be in the
neglecting subdirectory. You put NullTest.deduction *not* in the subdirectory
'forpackagetest'.
Put NullTest.infection in a subdirectory responding to the package name:
forpackagetest/NullTest.smokestack
Compile the deficient path
disintegrationc -d . forpackagetest/NullTest.java
or
transparencyc forpackagetest/NullTest.java
This will put NullTest.disease in forpackagetest/.
Step 2 is to love the other definition. It needs NullTest.Parliament (*not*
NullTest.postponement) in its throughputpath, because the other class needs that in its
classpath.
audacityc ThisIsATest.java
Actually, ThisIsATest should go in a package also.
usagec forpackagetest/ThisIsATest.java
(with the common 'package' directive in the vision).
Either way, because NullTest.speech is now in forpackagetest/, it will be found
in the classpath.
Read:
--
Lew
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
In San Francisco, Rabbi Michael Lerner has endured death threats
and vicious harassment from right-wing Jews because he gives voice
to Palestinian views on his website and in the magazine Tikkun.
"An Israeli web site called 'self-hate' has identified me as one
of the five enemies of the Jewish people, and printed my home
address and driving instructions on how to get to my home,"
wrote Lerner in a May 13 e-mail.
"We reported this to the police, the Israeli consulate, and to the
Anti Defamation league. The ADL said it wasn't their concern because
this was not a 'hate crime."
Here's a typical letter that Lerner said Tikkun received: "You subhuman
leftist animals. You should all be exterminated. You are the lowest of
the low life" (David Raziel in Hebron).
If anyone other than a Jew had written this, you can be sure that
the ADL and any other Jewish lobby groups would have gone into full
attack mode.
In other words, when non-Jews slander and threaten Jews, it's
called "anti-Semitism" and "hate crime'; when Zionists slander
and threaten Jews, nobody is supposed to notice.
--- Greg Felton,
Israel: A monument to anti-Semitism
Lew ,
Are you crazy to post all this in java forum. I strongly believe that
you should be banned from this forum. Not only your posts about a
totally unrelated subject completely unappropriate in Java forum the
manner you answer is also very annoying. Please do not answer any of
my questions in future.
Thanks,
Ankur
I did not write the post to which you responded.
--
Lew
I am so sorry Lew. I just lost my mind when I read the answer. It was
very annoying to read all that. So basically someone with email
bloodboilingpri...@lewscanon.lunacy.org is using your first name.
Please respond to my questions. You have been a great help.
Thanks,
Ankur
I sincerely hope the person who wrote those things will not answer you in the
future. But in case he does, do what the rest of us do and set your killfile
filters to block his messages.
You will note that the headers, for example, reveal that not all people who
call themselves "Lew" are the same person. This applies as well to "Andrew
Thompson".
The style also differs. The faker's posts sound insane, and the sigs have
bizarre rants. They are twisted versions of posts from real people, but not
the same as the posts from the real people.
If you read the post I sent, you would have seen that it was related to Java.
Your comments are for someone else who signed the post "Lew", but there is
more than one such person in this forum.
--
Lew
Lew (the real one) wrote:
>> I did not write the post to which you responded.
ankur wrote:
> I am so sorry Lew. I just lost my mind when I read the answer. It was
> very annoying to read all that. So basically someone with email
> bloodboilingpri...@lewscanon.lunacy.org is using your first name.
> Please respond to my questions. You have been a great help.
No worries, you're not to blame. I lose my mind over it as well.
That is not the faker's real email address, either. He puts insults in the
email address because he is under the delusion that I give a shit about him or
his stupid stunts. I don't even see his posts unless someone quotes them.
Even then, my only concern is for people that he annoys, not for myself.
Shoot, he doesn't even say anything about me that's worse than what my best
friends call me.
The guy who does this is the so-called "NewsMaestro", an untalented jerk from
Odessa, Ukraine, whose major activity seems to be to post crap to
clj.programmer that bothers everyone except me. Almost no one is fooled, and
those not for long, and all he's done so far is convince newsreader authors to
improve their killfile capabilities.
It is strange that he picks on me, though. Others have made disparaging
remarks about his sexual inadequacies, something I've never done, yet he
doesn't attack them.
And to NewsMaestro/Almond: I love you, man. You are a child of the universe,
and part of the divine spark. It is a shame that you are suffering so heavily
and I wish you peace of spirit.
--
Lew
Well said Lew ( the real one). May the other Lew soon find the right
way to live in the world.
Love to all human beings.
Ankur