cannot find symbol in java

感情迁移 提交于 2019-12-18 09:39:24

问题


This is in DFM.java

This part is in the main class

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));

This is in 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");
    }
}

Error

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

But when I ran with calls of eij method in commentary

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

This part where dx is of the vect class, worked well and is the code is similar to the matrix class

Can anyone help please?


回答1:


Looks like the signature of your matrix-class's get-method is missing the modifier public:

 double get(int i,int j)

so it has "default" (package) visibility. Change it to

 public double get(int i,int j)

and it should work.



来源:https://stackoverflow.com/questions/15039852/cannot-find-symbol-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!