简体   繁体   中英

Invalid method declaration; return type required

I'm writing a method to extract a certain substring, but I'm having problems calling that method. Code is as follows:

public void start() {
        String inputString = "XOXOXOO     X     XXO         X     OXO   ";

        int row = 0;
        int length = inputString.length();

        System.out.println("Enter column for X:");
        int column = Integer.parseInt(Keyboard.readInput());
    }
        enterToken("X", inputString,column);

     private String enterToken(String tokenSymbol, String inputString, int column){
         String columnEdit = inputString.substring(column*6-6,column*6); 

        String columnEdit1 = columnEdit.trim( );
        String columnEdit2 = columnEdit1+tokenSymbol+"                 ";
        String columnEdit3 = columnEdit2.substring(0,6);
        System.out.println(columnEdit3);
        return columnEdit3;

        }

I'm getting error "Invalid method declaration; return type required". I feel sure I declared it properly..

enterToken("X", inputString,column);

You need to add return type for this line (or) this line should go inside a method.

  System.out.println("Enter column for X:");
    int column = Integer.parseInt(Keyboard.readInput());
enterToken("X", inputString,column); 
}
}     
enterToken("X", inputString,column); 

Should be

enterToken("X", inputString,column); 
}     

Just to clarify what is happening here. The compiler thinks that you are trying to declare a method called "enterToken" but before it even parses the rest of the line it notices that you don't have a return type (or void) to begin with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM