Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Packages and access mode problem

Reply
Thread Tools

Packages and access mode problem

 
 
Neroku
Guest
Posts: n/a
 
      12-23-2006
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

 
Reply With Quote
 
 
 
 
Alan Krueger
Guest
Posts: n/a
 
      12-23-2006
Neroku wrote:
> 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.
 
Reply With Quote
 
 
 
 
Jhair Tocancipa Triana
Guest
Posts: n/a
 
      12-23-2006
Neroku <> writes:

> Alan Krueger ha escrito:


>> Neroku wrote:
>> > 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.


> 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()

--
-- Jhair
 
Reply With Quote
 
Neroku
Guest
Posts: n/a
 
      12-23-2006

Alan Krueger ha escrito:

> Neroku wrote:
> > 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.


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?

 
Reply With Quote
 
Ehsan Khoddam mohammadi
Guest
Posts: n/a
 
      12-24-2006
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.
> 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


 
Reply With Quote
 
Neroku
Guest
Posts: n/a
 
      12-24-2006

Ehsan Khoddam mohammadi ha escrito:

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


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)

 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      12-25-2006

Neroku wrote:
> 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


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.

 
Reply With Quote
 
Rajdeep
Guest
Posts: n/a
 
      12-26-2006
I think u should use import statement.
import A;
it will solve the problem.
Neroku wrote:
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search Engine Optimization Packages India, SEO Packages Hyderabad,SEO Packages Firm visioninfosyslinks@gmail.com HTML 0 12-20-2007 08:45 AM
mmm-mode, python-mode and doctest-mode? Edward Loper Python 0 08-09-2007 05:40 AM
re: mmm-mode, python-mode and doctest-mode? John J Lee Python 0 08-07-2007 07:49 PM
re: mmm-mode, python-mode and doctest-mode? Edward Loper Python 0 08-07-2007 08:58 AM
mmm-mode, python-mode and doctest-mode? John J Lee Python 3 12-01-2005 08:35 PM



Advertisments