我在更改按钮的可见性时遇到问题。每当我使用 setVisibility() 方法时,我都会得到一个 nullPointerException。这是我得到的错误:
04-08 15:59:02.529: E/AndroidRuntime(2807): FATAL EXCEPTION: main
04-08 15:59:02.529: E/AndroidRuntime(2807): java.lang.NullPointerException
04-08 15:59:02.529: E/AndroidRuntime(2807): at com.android.Rides.RideTracking.onClick(RideTracking.java:307)
04-08 15:59:02.529: E/AndroidRuntime(2807): at android.view.View.performClick(View.java:4204)
04-08 15:59:02.529: E/AndroidRuntime(2807): at android.view.View$PerformClick.run(View.java:17355)
04-08 15:59:02.529: E/AndroidRuntime(2807): at android.os.Handler.handleCallback(Handler.java:725)
04-08 15:59:02.529: E/AndroidRuntime(2807): at android.os.Handler.dispatchMessage(Handler.java:92)
04-08 15:59:02.529: E/AndroidRuntime(2807): at android.os.Looper.loop(Looper.java:137)
04-08 15:59:02.529: E/AndroidRuntime(2807): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-08 15:59:02.529: E/AndroidRuntime(2807): at java.lang.reflect.Method.invokeNative(Native Method)
04-08 15:59:02.529: E/AndroidRuntime(2807): at java.lang.reflect.Method.invoke(Method.java:511)
04-08 15:59:02.529: E/AndroidRuntime(2807): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-08 15:59:02.529: E/AndroidRuntime(2807): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-08 15:59:02.529: E/AndroidRuntime(2807): at dalvik.system.NativeStart.main(Native Method)
这是代码:
public View btnStart = null;
public View btnPause = null;
public View btnResume = null;
case R.id.btnPauseRide:
mLoggerServiceManager.pauseGPSLogging();
setResult( RESULT_OK, intent );
btnPause.setVisibility(View.GONE);
btnResume.setVisibility(View.VISIBLE);
break;
case R.id.btnResumeRide:
mLoggerServiceManager.resumeGPSLogging();
setResult(RESULT_OK, intent);
btnResume.setVisibility(View.GONE);
btnPause.setVisibility(View.VISIBLE);
default:
break;
任何帮助将不胜感激。