Issues with package declarations

A

ankur

This is what my class path contains:

..;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
 
A

Arne Vajhøj

ankur said:
This is what my class path contains:

.;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 ?

Package structure and directory structure must match.

package forpackagetest;

means that the files mus be:

forpackagetest\NullTest.java
forpackagetest\NullTest.class

Arne
 
A

ankur

ankur said:
This is what my class path contains:
.;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
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 ?

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 ?
 
A

Arne Vajhøj

ankur said:
ankur said:
This is what my class path contains:
.;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 ?
Package structure and directory structure must match.

package forpackagetest;

means that the files mus be:

forpackagetest\NullTest.java
forpackagetest\NullTest.class

So u r saying that I should create forpackagetest folder under C:\Java
Files manually.
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
 
A

ankur

ankur said:
ankur wrote:
This is what my class path contains:
.;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 ?
Package structure and directory structure must match.
package forpackagetest;
means that the files mus be:
forpackagetest\NullTest.java
forpackagetest\NullTest.class
So u r saying that I should create forpackagetest folder under C:\Java
Files manually.
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 ).
 
A

ankur

ankur said:
ankur wrote:
This is what my class path contains:
.;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 ?
Package structure and directory structure must match.
package forpackagetest;
means that the files mus be:
forpackagetest\NullTest.java
forpackagetest\NullTest.class
So u r saying that I should create forpackagetest folder under C:\Java
Files manually.
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 ).
 
M

Mark Space

ankur said:
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....
 
A

Arne Vajhøj

ankur said:
ankur said:
ankur wrote:
This is what my class path contains:
.;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 ?
Package structure and directory structure must match.
package forpackagetest;
means that the files mus be:
forpackagetest\NullTest.java
forpackagetest\NullTest.class
So u r saying that I should create forpackagetest folder under C:\Java
Files manually. 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 !

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 forgot that.

So:

javac NullTest.java

or

javac -d .. NullTest.java

down in that dir.

Arne
 
A

ankur

ankur said:
ankur wrote:
ankur wrote:
This is what my class path contains:
.;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 ?
Package structure and directory structure must match.
package forpackagetest;
means that the files mus be:
forpackagetest\NullTest.java
forpackagetest\NullTest.class
So u r saying that I should create forpackagetest folder under C:\Java
Files manually.
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 !
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 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,
 
A

Arne Vajhøj

ankur said:
ankur said:
ankur wrote:
ankur wrote:
This is what my class path contains:
.;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 ?
Package structure and directory structure must match.
package forpackagetest;
means that the files mus be:
forpackagetest\NullTest.java
forpackagetest\NullTest.class
So u r saying that I should create forpackagetest folder under C:\Java
Files manually.
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 !
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 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

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
 
A

ankur

ankur said:
ankur wrote:
ankur wrote:
ankur wrote:
This is what my class path contains:
.;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 ?
Package structure and directory structure must match.
package forpackagetest;
means that the files mus be:
forpackagetest\NullTest.java
forpackagetest\NullTest.class
So u r saying that I should create forpackagetest folder under C:\Java
Files manually.
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 !
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 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

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

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,
 
M

Mark Space

ankur wrote:

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).
 
A

Arne Vajhøj

ankur said:
ankur said:
ankur wrote:
ankur wrote:
ankur wrote:
This is what my class path contains:
.;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 ?
Package structure and directory structure must match.
package forpackagetest;
means that the files mus be:
forpackagetest\NullTest.java
forpackagetest\NullTest.class
So u r saying that I should create forpackagetest folder under C:\Java
Files manually.
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 !
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 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
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)

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
 
A

Arne Vajhøj

Arne said:
ankur said:
ankur wrote:
ankur wrote:
ankur wrote:
ankur wrote:
This is what my class path contains:
.;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 ?
Package structure and directory structure must match.
package forpackagetest;
means that the files mus be:
forpackagetest\NullTest.java
forpackagetest\NullTest.class
So u r saying that I should create forpackagetest folder under
C:\Java
Files manually.
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 !
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 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
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)

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.

Make that:

java -cp .. testpack.testclass

Arne
 
A

ankur

ankur said:
My NullTest.java contains:
package forpackagetest;
public class NullTest { ...
My thisisatest.java contains:
import forpackagetest.*;
public class thisisatest { ...
So u [sic] r [sic] saying that I should create forpackagetest folder
under C:\Java Files manually.

That's "you are", not "u r".

To unite NullTest.committee. But see my comments below.

Yes, but you need those .decade files *in the caveat path*.

contention names should start with a lesser-case plate, and each homicide trick
likewise: ThisIsATest.diminution



The shirt justice even told you so!

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
 
A

ankur

I did not write the post to which you responded.

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
(e-mail address removed) is using your first name.
Please respond to my questions. You have been a great help.

Thanks,
Ankur
 
A

ankur

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top