Ok, there are 3 problems here and then 1 thing you probably want to add as Richard MacCutchan said (Checking if b is null)
1 - You need to call getFolders() using d:\\ not d:
2 - Your iterative loop will need to start from the 0 index not 1
3 - Use absolute pathing if you want recursion to work
Here is the code which should work for you.
PS: The null pointer exception is being thrown because you were calling the "getFolders" method by not using the entire path of the directory, but rather the name of the directory. So instead of 'd:\DirectoryName' you were passing in 'Directoryname', which would return null if you call "listFiles()" on it
static public void getFolders(String drive) {
try {
File a = new File(drive);
File b[] = a.listFiles();
for (int i = 0; i < b.length; i++) {
if (b[i].isDirectory() == true) {
String str = b[i].getAbsolutePath().toString();
System.out.println(str);
getFolders(str);
}
}
} catch (Exception er) {
System.out.println(er);
}
}
public static void main(String[] args) {
getFolders("d:\\");
}