-5
public class Combo {




     public void list() throws SQLException{
       ResultSet rs=connexion.getStats().executeQuery("select * from GROUP_FILIÈRE ");
      // ResultSetMetaData rsm=rs.getMetaData();
         String nom_fil[] = null; int i=0;   
       while( rs.next()){

           nom_fil[i]=rs.getObject(1).toString();

           System.out.println(' '+nom_fil[i]);
            i ++;
       }


    }



    public static void main(String args[]) throws SQLException{

          Combo cb=new Combo();

           cb.list();

    }

}

the problem is i don't know where is the problem

but what i want to do is geting some informations from database in a procedure and call this procedure in main

Idos
  • 15,053
  • 14
  • 60
  • 75
  • The problem is very clear. Read the duplicate – Idos Feb 21 '16 at 15:06
  • @Tunaki It won't help him to learn questions however, and it's not dup he is not asking to tell him what is NPE in general. – Roman C Feb 21 '16 at 15:16
  • Would be useful to know where exactly NPE is thrown... – Jaroslaw Pawlak Feb 21 '16 at 15:21
  • 1
    `String nom_fil[] = null;` ... `nom_fil[i]=...` ... always remember: `null` is not an array. – Tom Feb 21 '16 at 15:25
  • NPE *could* occur if `getObject(1)` returns null, but will definitely occur when `nom_fil[i]` is executed on the **null** `nom_fil` variable. *That* is where the problem is, and the stack trace told you the line. Of course, you didn't show us the stack trace, so that part is an educated guess. – Andreas Feb 21 '16 at 15:36

2 Answers2

1

You are initializing an array to null, and then try to access it at index [i]. You should use an array only when you know its fixed size, and initialize it to an new array of that size.

In your case, the size is not fixed, so the solution is to use a List rather than an array. You can later turn that list into an array if you wish, by using the toArray() method.

Yoav Gur
  • 1,366
  • 9
  • 15
0

You are trying to access null nom_fill array....
Try this ... String nom_fill[] = new String[number];

Sunoo
  • 1
  • 6