5 Replies Latest reply: Mar 7, 2009 1:42 PM by 843785 RSS

    Constructor and Undefined error

    843785
      The error it gives is that RealVector(double[]) is undefined. Yet it is defined and the constructors and the methods work with other programs.
      It accepts the rvArray definition.

      What am I doing wrong?
      Thanks!

      ***************** TestRealMatrix.java
      import java.util.*;
      
      public class TestRealMatrix {
      public static void main(String[] args) {
      double[] array1 = {1, 2, 3};
      double[] array2 = {4, 5, 6};
      double[] array3 = {7, 8, 9};
      
      ArrayList<RealVector> rvArray = new ArrayList<RealVector>();
      
      rvArray.add(new RealVector(array1));
      rvArray.add(new RealVector(array2));
      rvArray.add(new RealVector(array3));
      
      }
      }
      ***************** RealVector.java
      import java.util.*;
      
      /* this is declaring the class */
      public class RealVector {
      
           private Vector v1;
           
      /* This is a constructor that takes in arr1 from TestRealMatrix */
           public RealVector(double[] arr1) {
      
      /* This creates an element in v1 for each element in the array */
                v1 = new Vector();
                for (int index = 0;index < arr1.length; index++) {
                     v1.add(arr1[index]);
                }
           }
           
           public RealVector(ArrayList<Double> list1) {
      
                /* This creates an element in v1 for each element in the arraylist */
                          v1 = new Vector();
                          for (int index = 0;index < list1.size(); index++) {
                               v1.add(list1.get(index));
                          }
                     }
           
           
      }