Ok I had been having problems with nullpointerexceptions on a app I wrote. Here is what I found out:
Basically when you declare a reference variable (an object), you are really only creating a pointer. Its not like a primitive type variable.
Here is what I mean.
If you were to do this line of code
dim mynum as int
mynum = 2
Technically mynum was set to 0, then set to 10 in the second line. 10 is then put into the memory area designated by mynum
Now lets say, instead of setting it to 10, you set mynum to pull from an array that has yet to be created. Instead of setting it to 0 it sets it to nothing (IE:null) then points it to the array to get its insantiation.
The null pointer exception is thrown when you declare a variable but don't create the object for the variable. The app is expecting something where there is nothing.
Now by what you were saying it seems that you are forcing the webview to quit before instantiating the variable and hence the NullPointerException.
Couldn't you just write a catch that ,if the null is thrown, it ignores it.
Now this is just a guess, Im not sure if it would work but it might. But maybe something like this coded into your back button:
if mynum = null then
mynum=0 'or muynum = (whatever it is supposed to hold) so it isnt empty
'CODE FOR BACK BUTTON COPIED HERE
else
'CODE FOR BACK BUTTON COPIED HERE
end if
The idea being if mynum is null, instantiate it with some kind of data like it would have received had you not stopped the process. And if it is istantiated then just continue with the back button code.
That or if the code that mynum is supposed to hold does not matter after the back button is pushed, just write a line of code at the beginning of the back button sub that states:
this way as soon as you push the back button it fills the variable and moves on.
Like I said I have no idea if it will work, but I would think that if you caught the empty variable before you threw the exception you would be able to stop it from throwing it.
That is about the only thing i can think of.
Thanx
George