2016-11-03 69 views
-1

這是我不斷收到並且不確定如何更正它的錯誤。RuntimeException:不可編譯的源代碼(Netbeans)

異常在線程 「主」 了java.lang.RuntimeException:不可編譯 源代碼 - 在 salescommission.SalesCommission.main(SalesCommission.java:27)表達的非法起動

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package salescommission; 

/** 
* 
* @author Michael 
*/ 
public class SalesCommission { 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args){ 
     // public class SalesCommission { 
    // fixed salary variable 
    double fixedSalary; 
    // variable of the value of sale person's annual sales 
    double annualSales; 
    //the commission earned 
    double commission; 


    private final double annualSales; 
    private double commission; 
    private double fixedSalary; 
    public SalesCommission(double annualSales){ 
     this.annualSales=annualSales; 
     double commission = 0.25*annualSales; //The current commission 25% of total sales. 
     int fixedSalary = 75000; // set fixed salary is 75000$ 
    } 
    public double getTotalAnnualCompensation(){// calculate The total annual compensation is the fixed salary plus the commission earned 
     return fixedSalary+commission; 
    } 
} 

回答

0

把類變量和方法定義放在main方法之外,那麼它應該工作。

1

你只需在雙重佣金後忘記「}」 :-)

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package salescommission; 

/** 
* 
* @author Michael 
*/ 
public class SalesCommission { 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) { 
     // public class SalesCommission { 
     // fixed salary variable 
     double fixedSalary; 
     // variable of the value of sale person's annual sales 
     double annualSales; 
     //the commission earned 
     double commission; 
    } 
    private final double annualSales; 
    private double commission; 
    private double fixedSalary; 

    public SalesCommission(double annualSales) { 
     this.annualSales = annualSales; 
     double commission = 0.25 * annualSales; //The current commission 25% of total sales. 
     int fixedSalary = 75000; // set fixed salary is 75000$ 
    } 

    public double getTotalAnnualCompensation() {// calculate The total annual compensation is the fixed salary plus the commission earned 
     return fixedSalary + commission; 
    } 
} 

但隨後的代碼沒有任何意義,你必須運行在主方法的方法:O)

0

這不是一個Netbeans的錯誤...你的主要方法沒有一個閉合大括號:)

public static void main(String[] args) { 
    // public class SalesCommission { 
    // fixed salary variable 
    double fixedSalary; 
    // variable of the value of sale person's annual sales 
    double annualSales; 
    //the commission earned 
    double commission; 
}