簡體   English   中英

如何修復項目構建路徑錯誤? 我無法為 Java 8/9 計算器應用程序導入 java.lang.math

[英]How can I fix the project build path error? I can't import the java.lang.math for a Java 8/9 Calculator app

我正在 Eclipse 中的 Java 8/9 中開發一個簡單的計算器應用程序。 我正在研究冪運算(如數學中使用的“冪”)。 我想使用Math.power()而不是for循環。 但是,我無法將 java 數學 package 導入程序。 互聯網上說要添加import java.lang.math 當我嘗試對其進行編碼時,我收到“無法執行操作。此編譯單元不在 Java 項目的構建路徑上”的通知。 我忽略了什么和/或做錯了什么? 請提供建議或反饋。

請注意:是的,這是一項學術作業。 為了清楚起見,我不是要求對電源操作進行編碼。 這個問題專門關於導入數學 package。

電源操作(power.java)

package org.eclipse.example.calc.internal.operations;

import org.eclipse.example.calc.BinaryOperation;
// import java.lang.math; produces error 

// Binary Power operation

public class Power extends AbstractOperation implements BinaryOperation {
     // code removed. not relevant to SOF question.    
}

主要(calculator.java)

package org.eclipse.example.calc.internal;

import org.eclipse.example.calc.BinaryOperation;
import org.eclipse.example.calc.Operation;
import org.eclipse.example.calc.Operations;
import org.eclipse.example.calc.UnaryOperation;
import org.eclipse.example.calc.internal.operations.Power;
import org.eclipse.example.calc.internal.operations.Equals;
import org.eclipse.example.calc.internal.operations.Minus;
import org.eclipse.example.calc.internal.operations.Plus;
import org.eclipse.example.calc.internal.operations.Divide;
import org.eclipse.example.calc.internal.operations.Square;



public class Calculator {

    private TextProvider textProvider;

    private String cmd;

    private boolean clearText;

    private float value;

    public static String NAME = "Simple Calculator";

    public Calculator(TextProvider textProvider) {
        this.textProvider = textProvider;
        setupDefaultOperations();
    }

    private void setupDefaultOperations() {
        new Power();
        new Equals();
        new Minus();
        new Plus();
        new Divide();
        new Square();
    }

....

順便說一句,我通常使用駱駝案例,但學術項目名稱包括標准書寫格式的文件名。

編輯:閱讀回復后,我意識到我忘記提及這一點。 我只能輸入import java. ,然后彈出錯誤消息。 然后我不能輸入import語句的rest

package 層次結構的圖像

您的項目配置不正確。 你根本沒有源目錄。 src目錄應標記為源目錄; 右鍵單擊它並告訴 eclipse 關於這個,或者,因為它是一個 maven 項目,它更可能是一個損壞的 pom。 另外,您為什么使用org.eclipse package? 如果你為 SAP 工作,它應該是 com.sap。

暫無
暫無

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

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