Search code examples
javastatic-methodsnon-static

error: non-static method PostFixConverter(String) cannot be referenced from a static context


I'm doing some hw and am currently stumped. It gives an interface and a class for ArrayStack and asks to write a code that converts infix to postfix. In my main method is this line

PostFixConverter(infixExpression);  

which calls to a method that calculates the postfix expression. My problem is that the class ArrayStack is not static but my main method is, so how can I resolve this?

Also,

Am I converting infix to postfix wrong by not making a new class that calculates postfix because all other code I've seen that does this has a separate class for it? Is there an advantage to doing it that way?

Thank You!


Solution

  • For first query refer below:

    public static void main (String[] args)
    {
        String infixExpression = "Your infix string";
        PostFixConverter(infixExpression);  
    }
    
    private static void PostFixConverter(String infixExpression) 
    {
        //your code goes here
    }
    

    For second query, it's your choice to do it that way.