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 / First Aid / October 2004

Tip: Looking for answers? Try searching our database.

Cannot execute method in another class!

Thread view: 
Rio - 26 Oct 2004 14:37 GMT
I'm working in NetBeans and have 2 classes:

Class A that has a main method and calls methodB that is contained within
Class B and is declared public and static but I get "cannot resolve symbol
method B" error.

The same code works when methodB is placed within Class A.

Putting package mario.com at the start of both classes didn't help, so what
might be the problem!

Help appreciated!
_Mario_ - 26 Oct 2004 14:56 GMT
> I'm working in NetBeans and have 2 classes:
>
> Help appreciated!

...also significative code...

Mario
Paul Lutus - 26 Oct 2004 16:56 GMT
>> I'm working in NetBeans and have 2 classes:
>>
>> Help appreciated!
>
> ...also significative code...

Here you ask for code. Doesn't it occur to you that we need to see yours
first?

Signature

Paul Lutus
http://www.arachnoid.com

Peter Kirk - 26 Oct 2004 14:58 GMT
> I'm working in NetBeans and have 2 classes:
>
[quoted text clipped - 6 lines]
> Putting package mario.com at the start of both classes didn't help, so what
> might be the problem!

How exactly do you try to call "methodB" in ClassB?

You need an instance of your ClassB on which to call methodB. But then
again, as methodB is static you call it like this:
ClassB.methodB();

Peter
Rio - 26 Oct 2004 15:10 GMT
Whatever I try turns out wrong:

methodB();

doesnnot work nor

ClassB.methodB();

in my humble knowledge just methodB() should do the trick as the method is
static but it doesnnot.

> > I'm working in NetBeans and have 2 classes:
> >
[quoted text clipped - 15 lines]
>
> Peter
Paul Lutus - 26 Oct 2004 16:55 GMT
> Whatever I try turns out wrong:
>
[quoted text clipped - 6 lines]
> in my humble knowledge just methodB() should do the trick as the method is
> static but it doesnnot.

You have been asked several time to post your code. Maybe you should take
the advice. For lack of code, everyone is reduced to guessing, including
you.

Signature

Paul Lutus
http://www.arachnoid.com

Aki \ - 26 Oct 2004 15:09 GMT
> I'm working in NetBeans and have 2 classes:
>
[quoted text clipped - 6 lines]
> Putting package mario.com at the start of both classes didn't help, so what
> might be the problem!

Since you didn't post any code, it's impossible to tell exactly.
However, the most likely cause is that you have to use the dot (.)
operator to access a member of a class, whether it be a method or a
[public] variable.

Like this:

public class A{
    public static void main(String[] args){
        B.someMethod();   
    }
}
public class B{
    public static void someMethod(){
        //method implementation goes here
    }
}

> Help appreciated!

Posting the actual code of your program would be appreciated as well,
because it would be a tremendous help in tracking down just what goes
wrong and where.

Signature

-Aki "Sus" Laukkanen

Bryce - 26 Oct 2004 15:46 GMT
>I'm working in NetBeans and have 2 classes:
>
[quoted text clipped - 8 lines]
>
>Help appreciated!

could you post your code?

--
now with more cowbell
Hal Rosser - 27 Oct 2004 00:48 GMT
> I'm working in NetBeans and have 2 classes:
>
[quoted text clipped - 8 lines]
>
> Help appreciated!

AHA! I see what you're doing wrong.
The code is missing. You forgot to type it in and compile it.
Is the imaginary method declared static so you can call it from the other
class without instantiating it?
Rio - 27 Oct 2004 01:59 GMT
Thanks for all the replies but it really didn't have anything to do with
badly written code, I didn't put all the classes in the same package and
therefore I couldn't call method B from within Class A nor could I
instantiate an object of Class C from within Class b etc.

New Package -> and then copy paste of the code saved it!

Thanks!
Thomas G. Marshall - 27 Oct 2004 03:29 GMT
Rio coughed up:
> Thanks for all the replies but it really didn't have anything to do
> with badly written code, I didn't put all the classes in the same
[quoted text clipped - 4 lines]
>
> Thanks!

OI.  That is not a "real" solution in the long run, unless you truly intend
for the classes to be living "together" in package harmony (kumbaya)...

Learn about using fully qualified class names

   gurgle.spit.Splat.method();

or imports

   import gurgle.spit.Splat;
   ...
   Splat.method();

Signature

Framsticks.  3D Artificial Life evolution.  You can see the creatures
that evolve and how they interact, hunt, swim, etc. (Unaffiliated with
me). http://www.frams.alife.pl/

Andrew Thompson - 27 Oct 2004 06:04 GMT
> Thanks for all the replies but it really didn't have anything to do with
> badly written code,

Nobody suggested that before now.

Aki, Paul and Hal were all asking for an example of what
you were doing.  Here are some further points on examples..
<http://www.physci.org/codes/sscce.jsp>

....
> New Package -> and then copy paste of the code saved it!

See you next time* your IDE does something you do not
understand, that does not work as you hope it to.  I
suggest you abandon the IDE for the moment and figure how
to do these things from the command line.
<http://www.xdweb.net/~dibblego/java/faq/answers.html#q34>

( * Soon. )

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Thomas G. Marshall - 27 Oct 2004 15:30 GMT
Andrew Thompson coughed up:

...[rip]...

> See you next time* your IDE does something you do not
> understand, that does not work as you hope it to.  I
> suggest you abandon the IDE for the moment and figure how
> to do these things from the command line.

It has always been my position that rank beginners should /always/
thoroughly learn development from the command line *first*.  I'd put that in
200 point type if I could, with <BLINK> tags :) .  The only technologies I'd
suggest in the very beginning (but no further) would be

   vi, or the equivalent.  emacs {shudder} maybe.  Even ho hum textpad.
   make, but not necessary

Beginners should stay *away* from /any/ IDE until they feel like they
understand the command line, the compiler, the classpath, the package to
filesystem mapping, etc.

It's when folks are hazy on the fundamentals that they get utterly stuck in
more complicated (IDE) environments, where nearly all the details are
hidden.

The only possible exception to this rule of mine *might* be BlueJ, which
exists to teach OO fundamentals in java to beginners specifically /away/
from the grit and grime of the details----I don't know how to regard that
product yet, since I've never "taught" in it.

...[rip]...

Signature

"His name was Robert Paulson. His name was Robert Paulson. His name was
Robert Paulson..."

Bryce - 27 Oct 2004 14:49 GMT
>Thanks for all the replies but it really didn't have anything to do with
>badly written code, I didn't put all the classes in the same package and
>therefore I couldn't call method B from within Class A nor could I
>instantiate an object of Class C from within Class b etc.
>
>New Package -> and then copy paste of the code saved it!

No it didn't fix your problem. I suspect it was a work around.

Classes don't need to be in the same package to instantiate each other
or call methods from other classes... That would really be pointless,
don't you think?

--
now with more cowbell
Oscar kind - 27 Oct 2004 18:17 GMT
> Classes don't need to be in the same package to instantiate each other
> or call methods from other classes... That would really be pointless,
> don't you think?

Indeed: how would you create a List of String's if that were true?

Signature

Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2

Thomas G. Marshall - 27 Oct 2004 03:26 GMT
Hal Rosser coughed up:
>> I'm working in NetBeans and have 2 classes:
>>
[quoted text clipped - 13 lines]
> Is the imaginary method declared static so you can call it from the
> other class without instantiating it?

YES!  I cut and pasted his blank space code example and got nothing working
either.

Signature

Framsticks.  3D Artificial Life evolution.  You can see the creatures
that evolve and how they interact, hunt, swim, etc. (Unaffiliated with
me). http://www.frams.alife.pl/

Bjorn Abelli - 29 Oct 2004 23:34 GMT
"Thomas G. Marshall" wrote...
>> "Rio" wrote...

>>> Help appreciated!
>>
[quoted text clipped - 5 lines]
> YES!  I cut and pasted his blank space code example
> and got nothing working either.

Maybe he's programming in another language and is simply in the wrong group?

http://compsoc.dur.ac.uk/whitespace/

// Bjorn A


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.