![]() |
Why will this block not complie?
Code:
public void memberRegister(String newName, String newId, int newPinNumber) |
String 'storeName' is not declared; presumably Member is outside this block... need more code and error message to give an accurate answer though
|
Ok sorry didnt provide enough info.
storeName is a field in the class, so thats valid. Error on this line: Member.welcomeMessage(String name, String id, String storeName); Says this: ')' Expected |
I'm not seeing it... can you post entire class?
|
You can't call a method like that. It expects those argument datatypes, you cannot respecify them in the method call itself. Give it name, id and storename, not String name, ... instead.
|
I can't believe I didn't catch that :| it looked so correct for a constructor the fact the method call was bad eluded me *smack
|
Can you fix it for me.
Here is the store class: Code:
public class StoreCode:
/** |
Yeah, use this:
Member.welcomeMessage(name, id, storeName);. |
Quote:
non-static method welcomMessage(java.lang.String,java.lang.String,java.lang.String) cannot be referenced from a static context |
You need to provide it with an object then. WelcomeMessage is a non-static method, so it must be called on an instance of an object.
|
How do I do that?
|
The only direct way to do it with the code you have here is to instantiate a new member within the method memberRegister. I would assume that memberRegister should be doing something with Member anyway, so that may be a fine place to construct a new member.
|
Instantiating a Member object would depend on the constructors available.
Here's an example of instantiating a Member if it has a default constructor (no arguments) Code:
public void memberRegister(String newName, String newId, int newPinNumber)http://docs.oracle.com/javase/tutori...structors.html |
Thanks for all your help. I have come across another problem if you dont mind helping me out.
Heres the link: http://www.codingforums.com/showthread.php?t=282258 |
| All times are GMT +1. The time now is 10:22 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.