So here is my code... It's about asking for house pricing and locations, but I keep getting a NullPointerException.
public class price {
int[] Hprice;
String [] Hlocation;
int i = 0;
public static void main(String[] args) {
price price = new price();
price.input();
}
public void input()
{
price price = new price();
Scanner scan = new Scanner(System.in);
System.out.println("what is the price of the house?");
int ansP = scan.nextInt();
price.Hprice[i]=ansP;
System.out.println("what is its location? (north,south,east,west)");
String ansL = scan.nextLine();
price.Hlocation[i]=ansL;
i +=1;
}
when i run this ii get a null pointer exception, i have tried to define every value in the array but i stil get the exception when i set Hprice = ansP. Does anyone know where the excpetion might be happening? Thanks!