| Author |
Cannot execute method in another class!
|
|
|
| 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_ 2004-10-26, 3:59 pm |
|
"Rio" <riolino_eatball@yahoo.com> wrote in message
news:clljv2$uap$1@ls219.htnet.hr...
> I'm working in NetBeans and have 2 classes:
>
> Help appreciated!
....also significative code...
Mario
| |
| Peter Kirk 2004-10-26, 3:59 pm |
|
"Rio" <riolino_eatball@yahoo.com> skrev i en meddelelse
news:clljv2$uap$1@ls219.htnet.hr...
> 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!
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
| |
| Aki \Sus\ Laukkanen 2004-10-26, 3:59 pm |
| Rio wrote:
> 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!
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.
--
-Aki "Sus" Laukkanen
| |
|
| 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.
"Peter Kirk" <peter> wrote in message news:417e57e8@news.wineasy.se...
>
> "Rio" <riolino_eatball@yahoo.com> skrev i en meddelelse
> news:clljv2$uap$1@ls219.htnet.hr...
within[color=darkred]
symbol[color=darkred]
> what
>
> 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
>
| |
|
| On Tue, 26 Oct 2004 15:37:37 +0200, "Rio" <riolino_eatball@yahoo.com>
wrote:
>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!
could you post your code?
--
now with more cowbell
| |
| Paul Lutus 2004-10-26, 3:59 pm |
| Rio wrote:
> 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.
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.
--
Paul Lutus
http://www.arachnoid.com
| |
| Paul Lutus 2004-10-26, 3:59 pm |
| _Mario_ wrote:
>
> "Rio" <riolino_eatball@yahoo.com> wrote in message
> news:clljv2$uap$1@ls219.htnet.hr...
>
> ...also significative code...
Here you ask for code. Doesn't it occur to you that we need to see yours
first?
--
Paul Lutus
http://www.arachnoid.com
| |
| Hal Rosser 2004-10-27, 3:58 am |
|
"Rio" <riolino_eatball@yahoo.com> wrote in message
news:clljv2$uap$1@ls219.htnet.hr...
> 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!
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?
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.781 / Virus Database: 527 - Release Date: 10/21/2004
| |
|
| 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 2004-10-27, 3:58 am |
| Hal Rosser coughed up:
> "Rio" <riolino_eatball@yahoo.com> wrote in message
> news:clljv2$uap$1@ls219.htnet.hr...
>
> 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?
YES! I cut and pasted his blank space code example and got nothing working
either.
--
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/
| |
| Thomas G. Marshall 2004-10-27, 3:58 am |
| 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
> 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!
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();
--
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/
| |
|
|
|
| On Wed, 27 Oct 2004 02:59:42 +0200, "Rio" <riolino_eatball@yahoo.com>
wrote:
>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
| |
| Thomas G. Marshall 2004-10-27, 3:59 pm |
| 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]...
--
"His name was Robert Paulson. His name was Robert Paulson. His name was
Robert Paulson..."
| |
| Oscar kind 2004-10-27, 3:59 pm |
| Bryce <spamtrap@berzerker-soft.com> wrote:
> 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?
--
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
| |
| Bjorn Abelli 2004-10-29, 8:57 pm |
|
"Thomas G. Marshall" wrote...
> Hal Rosser wrote:
[color=darkred]
>
> 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
|
|
|
|