我有任务要做,我有一点有问题,我遇到了错误。我不知道如何修复它:
test.main(test.java:29) 处的线程“main”java.lang.NullPointerException 中的异常
这是我的代码:
import java.util.Scanner;
public class test
{
static int size;
static String[] productDescription;
public static void readProductsData()
{
Scanner data = new Scanner(System.in);
System.out.print("Array size: ");
size = data.nextInt();
String[] productDescription = new String[size];
for(int i = 0; i < size; i++)
{
System.out.print("Product name: ");
productDescription[i] = data.next();
}
for(int i = 0; i < size; i++)
System.out.println(productDescription[i]);
}
public static void main(String[] args)
{
readProductsData();
System.out.println(productDescription[0]);
}
}