What line is throwing the error? Something is null on that line. What are you dereferencing?

Step through your code with a debugger, or at least add some print statements, to figure out what's...