java程序编译得非常好,但在运行其drop时,字符串输入会出错
程序编译得非常好,但在运行其drop时,UserInputWindows方法中的字符串输入出现错误。我以前写过一个类似这样的while循环,没有任何问题,但我似乎无法理解为什么它现在给了我一个错误。程序还远没有完成,我只是很快地运行它,看看是否有任何错误。下面是编码器
enter code here
import java.util.Scanner;
public class PaintEstimate
{
final static double WallAndCeilingPaintCost = 18.50;//cost for 1 gallon
//final static double WhiteEnamelPaintCost = 9.50; //cost for 1 quart//using only for refrence now//changed to _MoldingCostPerQuart
//final static double ColorEnamelPaintCost = 12.50; //cost for 1 quart//using only for refrence now// changed to _MoldingCostPerQuart
final static double CoverageOfWallAndCeilingPaint = 250.00; // coverage of wall and ceiling paint in sqft
final static double CoverageOfEnamelPaint = 100.00;// coverage of enamel paint both color and whit in linear sqft
public static double IntchesToFeet;
public static double RoomSquareFeet, CeilingSqaureFeet;
public static double InchRoomWidth, InchRoomLength, InchRoomHeight;
public static double FeetRoomWidth, FeetRoomLength, FeetRoomHeight;
public static double NumberOfWindows, NumberOfDoors;
public static double InchesWindowsHeight, InchesWindowsLength, InchesWindowsMoldingWidth;
public static double InchesDoorsHeight, InchesDoorsLength, InchesDoorsMoldingWidth;
public static String WindowsMoldingColorOrWhite, DoorsMoldingColorOrWhite;
public static double WindowsMoldingCostPerQuart = 0;
public static double DoorsMoldingCostPerQuart = 0;
public static Scanner scan = new Scanner(System.in);
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
UserInputWallsAndCeiling();
UserInputWindows();
UserInputDoors();
}
public static void UserInputWallsAndCeiling()
{
System.out.println("What is the room height in inches? ");
InchRoomHeight = scan.nextDouble();
System.out.println("What is the room width in inches? ");
InchRoomWidth = scan.nextDouble();
System.out.println("What is the room length in inches? ");
InchRoomWidth = scan.nextDouble();
}
public static void UserInputWindows()
{
System.out.println("How many windows are in the room? ");
NumberOfWindows = scan.nextDouble();
if(NumberOfWindows > 0)
{
System.out.println("What are the windows height in inches? ");
InchesWindowsHeight = scan.nextDouble();
System.out.println("What are the windows length in inches? ");
InchesWindowsLength = scan.nextDouble();
System.out.println("What are the windows molding width in inches? ");
InchesWindowsMoldingWidth = scan.nextDouble();
System.out.println("Is the windows molding color or white? ");
boolean WindowsTrue = false;
while (!WindowsTrue)
{
System.out.println("Is the doors molding color or white? ");
DoorsMoldingColorOrWhite = scan.nextLine();
if ( WindowsMoldingColorOrWhite.equals("color"))
{
WindowsMoldingCostPerQuart = 12.50;
WindowsTrue = true;
}
else if (WindowsMoldingColorOrWhite.equals("white"))
{
WindowsMoldingCostPerQuart = 9.50;
WindowsTrue = true;
}
else
{
System.out.println("Please enter if the molding is color or white");
}
}
}
}
public static void UserInputDoors()
{
System.out.print("How many doors are in the room? ");
NumberOfDoors = scan.nextDouble();
if(NumberOfDoors > 0)
{
System.out.println("What are the doors height in inches? ");
InchesDoorsHeight = scan.nextDouble();
System.out.println("What are the doors length in inches? ");
InchesDoorsLength = scan.nextDouble();
System.out.println("What are the doors molding width in inches? ");
InchesDoorsMoldingWidth = scan.nextDouble();
boolean DoorsTrue = false;
while (!DoorsTrue)
{
System.out.println("Is the doors molding color or white? ");
DoorsMoldingColorOrWhite = scan.nextLine();
if ( DoorsMoldingColorOrWhite.equals("color"))
{
DoorsMoldingCostPerQuart = 12.50;
DoorsTrue = true;
}
else if (DoorsMoldingColorOrWhite.equals("white"))
{
DoorsMoldingCostPerQuart = 9.50;
DoorsTrue = true;
}
else
{
System.out.println("Please enter if the molding is color or white");
}
}
//System.out.print(InchesDoorsHeight + " " + InchesDoorsLength + " " + DoorsMoldingColorOrWhite + " " + DoorsMoldingCostPerQuart)
}
}
public static void IntchesToFeet()
{
FeetRoomWidth= InchRoomWidth / 12;
FeetRoomLength = InchRoomLength / 12;
FeetRoomHeight = InchRoomHeight / 12;
}
}
# 1 楼答案
这是一个简单的打字错误;)
门成型与窗成型
如果检查由此产生的NullPointerException,则代码#61的行直接指向If语句,该语句告诉您在该行或之前开始搜索:
线程“main”java中出现异常。lang.NullPointerException在PaintEstimate。UserInputWindows(PaintEstimate.java:61)