Exception in thread & ldquo; hand & rdquo; java.lang.NullPointerException handling ArrayLists

advertisements

I made this code that has the purpose of creating a ArrayList of strings filled as follow: -in a loop I take an ArrayList<String> , convert it into one long string then I hash it. -I take the hash of the version attributed to the array and hash it as well. Then I concatenate both hashes using a string Builder and add them into my ArrayList.

However, when I try to test by printing one of the results, I get this error:

Exception in thread "main" java.lang.NullPointerException
    at package_name.Keys.keys(Keys.java:29)     // this lign means value.append(hashsplit);

I don't understand whats wrong in the code. Can anybody have some suggestions? Thank you

Here is the code:

package package_name;

    import java.util.ArrayList;
    import java.util.List;

  public class Keys {

public static ArrayList<String>  keyStringArray  = new ArrayList<String>();

 public static List<String>  keys(){
long  x = MainClass.NUM_OF_SPLITS;

             for ( int i = 0; i < x+1 ; i++ ){
    ArrayList<String> a = MainClass.splits.get(i).blocks;
    String listString = "";

    for (String s : a)
    {
        listString += s + "\t";
    }

    int ver = MainClass.version[i]; //then we should get the version of the split
    String verr =  String.valueOf( ver );
    // hash the results.
    String hashsplit =OtherKeys.String2(listString);
    String hashversion = OtherKeys.String2(verr);
    StringBuilder value = null;
    value.append(hashsplit);
    value.append(hashversion);
     String key=   value.toString();
     keyStringArray.add(i, key);

    }

return  keyStringArray ; }}


 StringBuilder value = null;
 value.append(hashsplit);

where value is null.

create object of it and then use.

 StringBuilder value = new StringBuilder();
 alue.append(hashsplit);