|
| 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 |
|
|
|
| 02 Mar 2015 06:28 PM |
| You're calling computeLeastPath from a static method. |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2015 06:31 PM |
| I'm confused... how do I not make it a static method...? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 02 Mar 2015 06:42 PM |
@king yes this code is inside the main method.
|
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 02 Mar 2015 07:09 PM |
| Actually, it is also possible that you want to make computeLastPath a static method. |
|
|
| Report Abuse |
|
|