Code Comments
Programming Forum and web based access to our favorite programming groups.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!
Post Follow-up to this message"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
Post Follow-up to this message"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
Post Follow-up to this messageRio 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 wha
t
> 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
Post Follow-up to this messageWhatever 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 symbol > 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 >
Post Follow-up to this messageOn 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
Post Follow-up to this messageRio 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
Post Follow-up to this message_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
Post Follow-up to this message"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
Post Follow-up to this messageThanks 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!
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.