2013-03-02 164 views
-4

我有一个包含3个方法的类,它基本上用Java中的数组数组实现了一些基本的东西,但是当试图在我的主函数中调用这些方法时,我得到一个错误..任何人都可以告诉我什么问题是...我敢肯定它的一些愚蠢的错误基本:(在Java中调用方法时出错

class Matrix { 
    double[][] m = { {2,4,31,31}, 
        {3,3,21,41}, 
        {1,2,10,20}, 
        {3,2,20,30} }; 

    public static void negate(double[][] m){ 
     int r = m.length; 
     int c = m[r].length; 
     double[][] n = new double[c][r]; 
     for(int i = 0; i < n.length; ++i) { 
      for(int j = 0; j < n[i].length; ++j) { 
       n[i][j] = (m[i][j])*-1; 
      } 
     } 

    } 

    public static void transposeMatrix(double[][] m){ 
     int r = m.length; 
     int c = m[r].length; 
     double[][] t = new double[c][r]; 
     for(int i = 0; i < r; ++i){ 
      for(int j = 0; j < c; ++j){ 
       t[j][i] = m[i][j]; 
      } 
     } 

    } 

    public void print(double[][] n, double[][] t){ 
     int r = m.length; 
     int c = m[r].length; 

     for(int i = 0; i < r; ++i){ 
      for(int j = 0; j < c; ++j){ 
      System.out.print(" " + n[i][j]); 
      } 
      System.out.println(""); 
      } 

     for(int i = 0; i < r; ++i){ 
      for(int j = 0; j < c; ++j){ 
      System.out.print(" " + t[i][j]); 
      } 
      System.out.println(""); 
      } 
    } 
} 

现在这是主要的,我有..提前任何输入

public class testMatrix { 
    public static void main(String[] args){ 

     Matrix.negate(m); 
    } 

} 

感谢!

这是个错误...

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    m cannot be resolved to a variable 

    at testMatrix.main(testMatrix.java:5) 
+3

你得到什么错误实例变量? – mindandmedia 2013-03-02 00:48:43

+0

重建所有.... – jdb 2013-03-02 00:52:29

回答

4

Exception in thread "main" java.lang.Error: Unresolved compilation problem: m cannot be resolved to a variable at testMatrix.main(testMatrix.java:5)

通过看你的错误了很明显的,你需要的Matrix类的一个实例来访问其

Matrix.negate(new Matrix().m); 
相关问题