找不到java的符号(cannot find symbol in java)

2019-07-20 09:50发布

这是DFM.java

这部分是主类

Algebra.vect dx = new Algebra.vect(new double[] {2.0,3.0,4.0});
Algebra.matrix eij = new Algebra.matrix();
System.out.println(eij.get(1,1));
dx.set(1,4.0);
System.out.println(dx.get(1));

这是Algebra.java

class Algebra {
public static class vect
{
    double[] v = new double[3];
    public vect()
    {
        v[0]=v[1]=v[2]=0;
    }
    public vect(double[] v)
    {
        this.v=v;
    }
    int tamanho()
    {
        return v.length;
    }
    double get(int i)
    {
        return v[i];
    }
    void set(double[] v)
    {
        this.v=v;
    }
    void set(int i, double n)
    {
        v[i]=n;
    }
    void print()
    {
        for(int i=0; i < v.length; i = i + 1)
            System.out.print(v[i] + " ");
        System.out.print("\n");
    }
}

public static class operacoes
{
    double prodInt(vect v1, vect v2)
    {
        return v1.get(0)*v2.get(0)+v1.get(1)*v2.get(1)+v1.get(2)*v2.get(2);
    }
    double[] somaVV(vect v1, vect v2)
    {
        return new double[] {v1.get(0)+v2.get(0), v1.get(1)+v2.get(1), v1.get(2)+v2.get(2) };
    }
    double[] prodMV(matrix m, vect v)
    {                    
        double[] Soma = new double[3];
        Soma[0]=Soma[1]=Soma[2]=0;
        for(int i=0;i< v.tamanho();i=i+1)
        {
            for(int j=0;i< v.tamanho();j=j+1)
            {
                Soma[i]=m[i][j]*v[j];
            }
        }
        return Soma;
    }

}

public static class matrix
{
    double[][] m = new double[3][3];
    public matrix()
    {
        for(int i=0;i< v.tamanho();i=i+1)
        {
            for(int j=0;i< v.tamanho();j=j+1)
            {
                m[i][j]=0;
            }
        }
    }
    public matrix(double[][] m )
    {
        this.m=m;
    }
    double get(int i,int j)
    {
        return m[i][j];
    }
    void set(double [][] m)
    {
        this.m=m;
    }
    void set(int i,int j, double n)
    {
        m[i][j]=n;
    }
    void print()
    {
        for(int i=0;i< v.tamanho();i=i+1)
        {
            for(int j=0;i< v.tamanho();j=j+1)
            {
                System.out.print(m[i][j] + " ");
            }
            System.out.print("\n");
        }
        System.out.print("\n");
    }
}

错误

DFM.java:29: error: cannot find symbol
System.out.println(eij.get(1,1));
                      ^
symbol:   method get(int,int)
location: variable eij of type matrix
1 error

但是,当我跑在评论EIJ方法的调用

dx.set(1,4.0);
System.out.println(dx.get(1));

这部分,其中dx是VECT类的,运作良好,是代码类似于矩阵类

任何人都可以帮助吗?

Answer 1:

看起来像你的签名matrix -class的get -方法缺少修饰public

 double get(int i,int j)

所以它有“默认”(包)的知名度。 将其更改为

 public double get(int i,int j)

它应该工作。



文章来源: cannot find symbol in java