Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

Packages and access mode problem

Thread view: 
Neroku - 23 Dec 2006 15:15 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.
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.