我實現了一些代碼,包括隊列,當運行它,我得到一個NullPointerException.Please幫我解決它。我現在只是編寫代碼的縮寫形式。的NullPointerException在隊列
import java.util.*;
class ex
{
public static void main(String args[])throws IOException
{
Scanner in=new Scanner(System.in);
int i;
String s;
int n=in.nextInt();
Queue<Integer> q=null;
for(i=0;i<n;i++)
{
q.add(i);//I get the error in this line
}
System.out.println(q.size());
}
}