Java program to identify whether a given line is a comment or not : <p>I'm creating a java program to test if the given string is a comment or not and here's my code so far:</p>

<pre><code>public class comment {
public static void main(String args[]){
    String[] com = new String[50];
    Scanner scan = new Scanner(System.in);
    int i = 2 ,a=0;
    System.out.println("Enter comment");

   com[i] = scan.nextLine();

     if(com[0].equals("/")){
         if(com[1].equals("/")){
             System.out.println("comment");
         }
         else if (com[1].equals("*")){
         for(i=2;i&lt;=50; i++){
             if(com[1].equals("*") &amp;&amp; com[i+1].equals("/") ){
                 System.out.println("comment");
                 a=1;
                 break;
             }
             else{
                 continue;}}
         if(a==0){System.out.println("not");}
             }
         else{System.out.println("not");
         }
         }
      else{System.out.println("not");
         }
         }
     }
</code></pre>

<p>I'm getting an error on this line of code: </p>

<pre><code> if(com[0].equals("/"))
</code></pre>

<p>Error says: java.lang.NullPointerException</p>

<p>Any explanation on why is this occuring ?</p>
