My android app crashes on exit and during pivoting
<p>When I try to exit with the back button or try change the screen from portrait to landscape, the app crashes with the following error:</p>

<pre><code>04-28 15:53:28.866: WARN/dalvikvm(28501): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501): FATAL EXCEPTION: main
04-28 15:53:28.886: ERROR/AndroidRuntime(28501): java.lang.NullPointerException
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at feed.rider.feedapp.onKeyDown(feedapp.java:247)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at android.view.KeyEvent.dispatch(KeyEvent.java:1256)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at android.app.Activity.dispatchKeyEvent(Activity.java:2078)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1663)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at android.os.Looper.loop(Looper.java:123)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at android.app.ActivityThread.main(ActivityThread.java:3683)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at java.lang.reflect.Method.invokeNative(Native Method)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at java.lang.reflect.Method.invoke(Method.java:507)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-28 15:53:28.886: ERROR/AndroidRuntime(28501):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>
