为什么我从另一个类调用此方法时遇到问题?

fr0*_*0ps 1 java static

我是八年级学生,在java项目上有一个紧迫的截止日期.我已经准备好了我的GUI,除了我需要从两个文本字段中取两个值,并在按下按钮时将它们发送到另一个类中的方法.我无法调用我需要的方法.所有重要的代码如下.

试图调用该方法的代码:

 private void GoButtonActionPerformed(java.awt.event.ActionEvent evt) {                                         

    String Ntextfield = NumberTextField.getText();
    n = Integer.parseInt(Ntextfield);

    String Rtextfield = RateTextField.getText();
    r = Integer.parseInt(Rtextfield);
    //call PermMath class
    PermMath doTheMath = new PermMath();
    doTheMath.permutations(int n, int r);
}  
Run Code Online (Sandbox Code Playgroud)

方法我试图打电话:

class PermMath {
  static long factorial(int num){
      //other code is here
  }
  static long permutations(int n, int r){
        //code I want to call is here
  }
}
Run Code Online (Sandbox Code Playgroud)

ada*_*shr 5

您的提示是static关键字.了解它的含义和工作原理.

此外,您正在使用变量n,r甚至在声明变量之前.

n = Integer.parseInt(Ntextfield); 
Run Code Online (Sandbox Code Playgroud)

你做完之后应该来int n = 0;.

在调用方法时,不要声明参数.以下是错误的.

doTheMath.permutations(int n, int r);
Run Code Online (Sandbox Code Playgroud)

相反,你做的事情

doTheMath.permutations(n, r);
Run Code Online (Sandbox Code Playgroud)