title: What is wrong with this code? (Array of objects, null pointer exception.)
body: <p>I have created an array of objects for abc class, but it gives a null pointer exception whenever i call the <code>accept()</code> code which gets the data from the user.</p>
  
  <p>This is the code:</p>
  
  <pre class="lang-java prettyprint-override"><code>   class abc{
      int rollno,i;
      String name;
      public void accept(){
          Scanner sc=new Scanner(System.in);
          System.out.print("Enter roll no: ");
          rollno=sc.nextInt();
      }
  
      public void display(){
          System.out.println("Roll no: "+rollno);
      }
  
      public static void main(String[] gs){
          int i;
          abc a[]=new abc[10];
  
          for(i=0;i&lt;10;i++){
              a[i].accept();    //This line gives null pointer exception
          }
  
          for(i=0;i&lt;10;i++){
              a[i].display();
          }   
  }
  </code></pre>
  
  <p>Can anyone tell what is the problem?</p>