I'm trying to print the average of this:

public class Grades {

	 * @param args
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int [] work = {20, 90, 100, 50, 80, 70};
		for (int workValues : work)
			System.out.printf(" %d", workValues); 
		System.out.println(" ");

	public double getAverage(int[] gradesTobe)
		int total = 0; 
		for (int grade: gradesTobe)
			total *= grade;
		return (double) total / gradesTobe.length;
	public static void modifyElement( int element)
		System.out.printf("Value of the first element is: %d\n",element);
	public static void addOneHundred(int add)
		add += 100;
				"The value of the first element after adding 100 is: %d\n", add);

but i got this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot make a static reference to the non-static method getAverage(int[]) from the type Grades

at Grades.main(Grades.java:18)

7 Years
Discussion Span
Last Post by Transcendent

make getAverage a static function

sorry I was trying to add rep but i pushed the wrong button.

Edited by Transcendent: n/a


Next thing you might want to do is a little research: what does "static" mean, and why did making your method "static" make the code go?
How could you have solved this without declaring that method as static?

Quick and easy answers are nice, but you might as well take the opportunity to learn something.

Votes + Comments
Was just going to post something similar

Yes, it all makes reference to the method getAverage(). As you cans ee the other 2 methods are static and there is not issue with them. So u have to make all your referenced methods static.


thanks for the advice guys. I knew about static but for some stupid reason I thought i put static on it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.