작동중인 코드는 사용자의 입력을 받아들이려고하지만 프로그램을 실행할 때마다 java.land라는 오류가 있음을 계속 알려줍니다. nullexception : null입니다. 나는 무엇을 해야할지 모른다!java.lang.nullexception의 오류가 계속 발생합니다 : null
import java.util.Scanner;
public class HamzasGrocery
{
// instance variables - replace the example below with your own
private Scanner in;
/**
* Constructor for objects of class HamzasGrocery
*/
public HamzasGrocery()
{
Scanner in = new Scanner(System.in);
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public void sampleMethod()
{
double choice1;
double choice2;
double choice3;
double choice4;
double choice5;
double total;
System.out.print("Enter item #1: ");
System.out.println();
choice1 = in.nextDouble();
System.out.print("Enter item #2: ");
choice2 = in.nextDouble();
System.out.println();
System.out.print("Enter item #3: ");
choice3 = in.nextDouble();
System.out.println();
System.out.print("Enter item #4: ");
choice4 = in.nextDouble();
System.out.println();
System.out.print("Enter item #5: ");
choice5 = in.nextDouble();
System.out.println();
System.out.printf("%-10s", "Item #'s");
System.out.printf("%-10s", "Cost:");
System.out.printf("%-10s", "Total:");
}
}