Jump to content

Cannot find symbol when creating instance of another class


Mechagoober

Recommended Posts

I'm making a banking class along with my actual main class and I'm extending the GUI class as follows

Banking extends WoodCutter

Now, when I make an object of that class in my main as follows
 

Banking bank = new Banking();

bank.banking();

I have a banking method in my Banking class

However, I get these two errors when trying to make use of the bank method.
352f6ld.png

I would be grateful for some help. Thanks!

Edit: For further information I can get it to work if I just make the method inside the main, my point is I'm trying to figure out how to use classes but I'm not seeing what I am doing wrong.

Edited by Mechagoober
Link to comment
Share on other sites

Give use a bit more of your code, seeing structure would help tremendously for providing assistance. However, for starts lets not name your task bank. Rename it to something like banking -- what i usually do is a camelCase name of the class name for simplicity sake.

 

so you would have

Banking banking = new Banking();

 

Make sure your banking variable is a field and your instantiate it onStart() or whenever it should start. Set it to null initially.

Link to comment
Share on other sites

Pretty sure it isn't possible to extend your classes with the main class. Also don't use a while loop in your bank() method. If statement does the job. In your walk method you have double brackets in IF condition for no reason. What you should do is making a constructor in your bank class and pass the Methodprovider through it. No idea if I am explaining it right, here an example:

 

Public class Banking {
  
  	Methodprovider s;
 	public Banking (MethodProvider s) {
    this.s = s;
    }
      
  	public void bank() {
     // Here your banking method. 
    }
  
  
  
}

public class Woodcutter extends Script {
  
	public int onLoop() {
     Banking banking = new Banking(this);
      banking.bank();
      
      return 100;
    }
  
  
}

 

Link to comment
Share on other sites

Basically what undefeated said. You can only extend Abstract classes and WoodCutter is not. If you want to make your code cleaner and put it in different classes that's great. You could try to use inheritance here to put different tasks in different classes and "control" via an abstract "Task" class (search in forums to find some examples), or can do as you do now via states.

Try to do that Undefeated said and you should be ok. Pass me the Woodcutter object to banking and use the api methods there.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...