Jump to content

Cannot find symbol when creating instance of another class


Recommended Posts

Posted (edited)

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
Posted

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.

Posted

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;
    }
  
  
}

 

Posted

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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