0
int[] Data = null ;
    sp = set.replaceAll(" ", ",").split(",");

    for (int i=0 ; i<sp.length ; i++){

        Data[i] =Integer.parseInt(sp[i]);

}

In this java code i have this error "Exception in thread "main" java.lang.NullPointerException". In fact the int can not saved int value in Data[i]. What should i do to store that? Thanks

  • You've declared and initialized `Data` as `null`. Instead, create the array after your `split`. Like, `sp = set.replaceAll(" ", ",").split(","); int[] Data = new int[sp.length];` – Elliott Frisch Jul 24 '16 at 04:21
  • Thanks, It works :) –  Jul 24 '16 at 04:25

0 Answers0