我正在尝试编译此代码,但不断出现错误-
错误:/ Users / Pedro / Dropbox / school / java / Proj / exam 3 / EchoText.java:23:找不到符号
symbol:构造函数MultiPoint(java.lang.Double [])
位置:MultiPoint类

如果我在构造函数中省略了公共EchoText的数组,它将进行编译。但是,我需要它将数组作为参数传递给MultiPoint公共类。我的问题是,为什么它不与参数一起编译?该错误的确切含义是什么?

public class MultiPoint
{
    private double[] testCoord;

    public MultiPoint(double[] coordPt)
    {
      testCoord = coordPt;
    }

    public void printPoints()
    {
        for ( int i = 0; i < coordPt.length; i++ )
        {
            System.out.println("Coordinate # " + i + " : " + coordPt[ i ]);
        }
        System.out.println("");
    }
}

import java.util.Scanner;
import java.lang.Math;
import java.util.ArrayList;

public class EchoText
{
  private static String ans = null;

  public static double number, coord;
  private static int counter =0;
  private static ArrayList <Double> coordList = new ArrayList<Double>();
  public static void main(String[] args)
  {

    mainDeal();
    Double coordPt[] = new Double[ coordList.size() ];
    coordList.toArray(coordPt);

    for (Double list1 : coordPt)
    {
      System.out.println((counter + 1) + list1);
    }
    MultiPoint myMultiPoint = new MultiPoint(coordPt);
  }
   // HELP MENU CREATED BY PROF. BLANDO! I DO NOT TAKE CREDIT FOR THE HELP MENU TEXT!
   public static void helpMenu()
   {
     System.out.println("****************************** LAB 7 HELP MENU ******************************");
     System.out.println("\t\t\tBy Pedro Estrada");
     System.out.println("* This program defines a point in a N-Dimensional space. ");
     System.out.println("    - Each point can have different number of non-zero coordinate");
     System.out.println("    - You may request a random number for any coordinate by typing \"RANDOM\"");
     System.out.println("    - When you are finished entering the coordinate just press the <Enter> key");
     System.out.println();
     System.out.println("* Pairs of point are used to create a lines");
     System.out.println("    - If the 2 points have mismatched dimensions, the point from the lower-dimension space is");
     System.out.println("      converted to a higher dimension point with added coordinate of 0");
     System.out.println("    - When a line is created, the line distance is provided");
     System.out.println();
     System.out.println("* When you are done specifying points and lines type \"EXIT\" to display final operation statistics");
     System.out.println("* All key words are case insensitive and can be abbreviated");
     System.out.println("* Random number will be scaled between -1,000.00 and +1,000.00");
     System.out.println();
     System.out.println("****************************** LAB 7 HELP MENU ******************************");
   }
   public static String userPrompt()
   {
     Scanner keyboard = new Scanner(System.in);
     System.out.println("Enter a coordinate: [R]andom: [H]elp: [E]xit to exit program: Enter key  for next point:");
     return keyboard.nextLine();
   }
   public static void mainDeal()
   {

     /** I pulled some code from this website:
      * http://www.java-forums.org/new-java/19024-detect-enter-key-being-pressed.html
      */
      while(true)
      {
      ans = userPrompt();

      if((ans == null)|| (ans.length() == 0) ||(ans.trim().equals("")))
      {
         System.out.println("Exiting...");
         break;
      }
      else if (ans.trim().toUpperCase().charAt(0) == 'R')
      {
        coord = Math.random();
        counter++;
        coordList.add(coord);

      }
      else if (ans.trim().toUpperCase().charAt(0) == 'E')
      {
        System.exit(0);
      }
      else if (ans.trim().toUpperCase().charAt(0) == 'H')
      {
        helpMenu();
      }
      else
      {
        coord = Double.parseDouble(ans);
        counter++;
        coordList.add(coord);
      }
    }
   }

}

最佳答案

MultiPoint构造函数正在接受类型double[],如下所示:

public MultiPoint(double[] coordPt)


但是,当您创建MultiPoint的新实例时,您正在传递Double[]类型,如下所示:

Double coordPt[] = new Double[ coordList.size() ];
MultiPoint myMultiPoint = new MultiPoint(coordPt);

10-08 06:20