Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
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!




Report this thread to moderator Post Follow-up to this message
Old Post
Rio
10-26-04 08:59 PM


Re: Cannot execute method in another class!
"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



Report this thread to moderator Post Follow-up to this message
Old Post
_Mario_
10-26-04 08:59 PM


Re: Cannot execute method in another class!
"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


Report this thread to moderator Post Follow-up to this message
Old Post
Peter Kirk
10-26-04 08:59 PM


Re: Cannot execute method in another class!
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 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


Report this thread to moderator Post Follow-up to this message
Old Post
Aki \Sus\ Laukkanen
10-26-04 08:59 PM


Re: Cannot execute method in another class!
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 
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
>



Report this thread to moderator Post Follow-up to this message
Old Post
Rio
10-26-04 08:59 PM


Re: Cannot execute method in another class!
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

Report this thread to moderator Post Follow-up to this message
Old Post
Bryce
10-26-04 08:59 PM


Re: Cannot execute method in another class!
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


Report this thread to moderator Post Follow-up to this message
Old Post
Paul Lutus
10-26-04 08:59 PM


Re: Cannot execute method in another class!
_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


Report this thread to moderator Post Follow-up to this message
Old Post
Paul Lutus
10-26-04 08:59 PM


Re: Cannot execute method in another class!
"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



Report this thread to moderator Post Follow-up to this message
Old Post
Hal Rosser
10-27-04 08:58 AM


Re: Cannot execute method in another class!
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!



Report this thread to moderator Post Follow-up to this message
Old Post
Rio
10-27-04 08:58 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:42 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.