簡體   English   中英

RectangleTest.java:1:錯誤:程序包com不存在

[英]RectangleTest.java:1: error: package com does not exist

在我的大學課程中,我創建了一個Rectangle類,其長度和寬度屬性均默認為1。提供用於計算矩形的周長和面積的方法。 它具有長度和寬度的set和get方法。 設置方法應驗證長度和寬度是否均為大於0.0且小於20.0的浮點數。 編寫一個測試類Rectangle的程序。 就在我以為自己正在學習Java的時候,我碰到了這個問題,使我徹底不知所措。 我感到迷茫和迷茫。 在控制面板的環境變量中設置類路徑。 我已經做到了 我不了解目錄和子目錄位。 我下載了JUNIT並將其放在與Java項目相同的目錄中。 Rectangle.java會編譯,但RectangleTest.java不會。 我收到了臭名昭著的錯誤“包com不存在”。 我基本上迷路了。 誰能為我闡明這個問題。 這是兩個應用程序:

 package com.schweidel;
 public class Rectangle
 {
 private double length;//1 - 12
 private double width;//1 - 9
 private double perimeter;//1 - 217
 private double area;//1 - 108

 public void setPerimeter(double l, double w, double p, double a)//declaring and  inititalizing perimeter method
{
    length =((l > 0.00 && l < 20.00)? l: 1);
    width =((w > 0.00 && w < 20.00)? w: 1);
    perimeter =((p> 2.0*(length * width) && p < 217.00)? p: 1);
    area = ((a> length * width && a < 108.00)? a: 1);   
} //end method perimeter

public String toString()//defining toString method

{return String.format(“度量為:%.2f:%.2f:%.2f:%.2f”,長度,寬度,周長,面積); }} //結束類Rectangle

 Here is the test application, that does not compile.

 import com.schweidel;//import com.schweidel
 public class RectangleTest
 {
 public static void main(String[] args)
 {
 Rectangle rect = new Rectangle();//calls Rectangle constructor


 System.out.println(rect.toString());
 }//end method main
 }//end class RectangleTest

錯誤在這里:

import com.schweidel;

當您只能導入類時,您正在嘗試導入一個包( com.schweidel )。 您收到此錯誤消息是因為編譯器認為您要從名為com的包中導入名為schweidel的類。

您最有可能要通過編寫以下com.schweidelRectangleTest類添加到com.schweidel包中:

package com.schweidel;

如果您確實打算從com.schweidel導入類,則可以編寫import com.schweidel.*; 導入所有類,或import com.schweidel.(class name); 導入特定的類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM