Hello, Consider I have two folders: Ap and Bp. Each folder is a package
and has a source file, A.java and B.java respectively.
Those files contain the code below:
----------A.java-----------------------------------
package Ap;
public class A
{
public static void foo()
{
System.out.println("From A.foo()");
}
}
----------B.java-------------------------------
package Bp;
class B
{
public static void main(String []args)
{
Ap.A.foo();
}
}
It compiles fine, but when I run the B main method I get the following
error:
IllegalAccessException: Class
koala.dynamicjava.interpreter.EvaluationVisitor can not access a member
of class Bp.B with modifiers "public static"
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
I do not acces any member of class Bp.B, Any ideas??
TIA
Alan Krueger - 23 Dec 2006 15:46 GMT
> It compiles fine, but when I run the B main method I get the following
> error:
>
> IllegalAccessException: Class
> koala.dynamicjava.interpreter.EvaluationVisitor can not access a member
=================
> of class Bp.B with modifiers "public static"
> at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
>
> I do not acces any member of class Bp.B, Any ideas??
The "B main method" is a public static member of class Bp.B, so yes,
you're trying to access a method on Bp.B.
Also, it looks like you're trying to run this through DynamicJava
instead of the normal JVM.
Neroku - 23 Dec 2006 17:00 GMT
Alan Krueger ha escrito:
> > It compiles fine, but when I run the B main method I get the following
> > error:
[quoted text clipped - 10 lines]
> The "B main method" is a public static member of class Bp.B, so yes,
> you're trying to access a method on Bp.B.
So, I can't run the main method because the B class is not public, and
therefore the class that call the main method in B is unable to access
to it because both clases are not in the same package.
This explains the runtime error I get, right?
Jhair Tocancipa Triana - 23 Dec 2006 16:47 GMT
> Alan Krueger ha escrito:
>> > It compiles fine, but when I run the B main method I get the following
>> > error:
[quoted text clipped - 10 lines]
>> The "B main method" is a public static member of class Bp.B, so yes,
>> you're trying to access a method on Bp.B.
> So, I can't run the main method because the B class is not public, and
> therefore the class that call the main method in B is unable to access
> to it because both clases are not in the same package.
> This explains the runtime error I get, right?
Of course not.
(debian-unstable)jtocancipa@golem:~/tmp$ javac Ap/A.java
(debian-unstable)jtocancipa@golem:~/tmp$ javac Bp/B.java
(debian-unstable)jtocancipa@golem:~/tmp$ java Bp/B
From A.foo()

Signature
-- Jhair
Ehsan Khoddam mohammadi - 24 Dec 2006 01:45 GMT
HI
How do you invoke your class files with "java"
?
Neroku نوشته است:
> Hello, Consider I have two folders: Ap and Bp. Each folder is a package
> and has a source file, A.java and B.java respectively.
[quoted text clipped - 32 lines]
>
> TIA
Neroku - 24 Dec 2006 11:17 GMT
Ehsan Khoddam mohammadi ha escrito:
> HI
> How do you invoke your class files with "java"
[quoted text clipped - 36 lines]
> >
> > TIA
I click on the run botton in DrJava, but I do:
java B (current working directory is Bp)
I yields a different error.
I seems it only works fine if I do:
java Bp/B (current working directory is the parent of Bp)
Daniel Pitts - 25 Dec 2006 08:39 GMT
> Hello, Consider I have two folders: Ap and Bp. Each folder is a package
> and has a source file, A.java and B.java respectively.
[quoted text clipped - 32 lines]
>
> TIA
This looks more like a problem with koala.dynamicjava, whatever that
is.
I'm guessing you can solve this issue by change
"class B" to "public class B"
HTH
- Daniel.
Rajdeep - 26 Dec 2006 14:29 GMT
I think u should use import statement.
import A;
it will solve the problem.
> Hello, Consider I have two folders: Ap and Bp. Each folder is a package
> and has a source file, A.java and B.java respectively.
[quoted text clipped - 32 lines]
>
> TIA