它每次運行程序時都會得到java.lang.NullPointerException。甚至不會採取任何輸入。我真的不知道爲什麼會發生這種情況。java.lang.NullPointerException
另外,我有多少要解釋這個問題,所以stackoverflow將允許我發佈這個?
import java.util.Scanner;
import java.text.DecimalFormat;
public class A1Q2 {
Scanner keyboard = new Scanner(System.in); //declare scanner for keyboard input
DecimalFormat twoDform = new DecimalFormat("#.##");//declare decimal format for closest cent
double OP = 0; //original price of the car
double IntM = 0; // store the value of mileage
double FM = 0; //the mile age of the car
double Age = 0; //the age of the car
public static void main(String[] args) {
// DECLARE VARIABLES/DATA DICTIONARY
// Read in the original values
System.out.println("Please enter the original price of the car: ");
OP = keyboard.nextDouble();// taking input for the original price
//Read in the mileage factor
System.out.println("Please enter the mileage factor as 0.7(high),1(average) and 1.2(low):");
FM = keyboard.nextDouble();// taking input for the general mileage of the car
//Read in the age of cars
System.out.println("Place enter the age of the car :");
Age = keyboard.nextDouble();// taking input for the age of the car
// Display the result, Call method to estimate the current price of the car
System.out.println("Estimated price of the car is " + Calculation(Age, FM, OP) + " Dollers");
}
private String Calculation(double Age, double FM, double OP) {
// Declaration of the result variable
String EstPrice = "";
//estimate the current price of the car
EstPrice = twoDform.format(Math.sqrt(1.0/(Age + 1)) * FM * OP);
return EstPrice;
}
}
你能請張貼堆棧跟蹤? –
請包含完整的錯誤/堆棧跟蹤! –
它不是public void main(String [] args)它是'public static void main(String [] args){' – gtgaxiola