generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Difference between static and non-static functions (Java)

Previous Thread :: Next Thread 
MomoiroCloverZ is not online. MomoiroCloverZ
Joined: 06 Jan 2013
Total Posts: 825
02 Mar 2015 06:25 PM
My compiler keeps telling me that I'm making a static reference to a non-static method?

How is this line a static reference?

int distance = computeLeastPath(startPoint, endPoint, checkpoints, points, distances);
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
02 Mar 2015 06:28 PM
You're calling computeLeastPath from a static method.
Report Abuse
MomoiroCloverZ is not online. MomoiroCloverZ
Joined: 06 Jan 2013
Total Posts: 825
02 Mar 2015 06:31 PM
I'm confused... how do I not make it a static method...?
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
02 Mar 2015 06:35 PM
Remove the keyword 'static'. But chances are, if it is static then it is there for a reason.

Is this the 'main' method? Is there a specific object you created within the method you're working in that you want to use call it on (since your code currently implies a this.computeLeastPath which may not be what you want)?
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
02 Mar 2015 06:40 PM
Here is a little run down over static.

public class Example {

public static void run() {
System.out.println("Ran");
}

}

public class Example2 {

public void run() {
System.out.println("Ran2");
}
}

public class Main {

public static void main(String[] args) {
Example.run()
Example ex = new Example();
ex.run();
// or... new Example().run();
}

}
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
02 Mar 2015 06:41 PM
also static means stay the same throughout all classes - if one class indexes Example.x = 5; then in another class syso(Example.x) will yield 5.
Report Abuse
MomoiroCloverZ is not online. MomoiroCloverZ
Joined: 06 Jan 2013
Total Posts: 825
02 Mar 2015 06:42 PM
@king yes this code is inside the main method.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
02 Mar 2015 07:05 PM
Then have you created an object you want to call computeLeastPath on within the main method (or as an instance variable)?
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
02 Mar 2015 07:09 PM
Actually, it is also possible that you want to make computeLastPath a static method.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image