由于某些原因,当我将“可见性”设置为java.lang.RuntimeException: Could not find RESUMED activity on main thread
at com.snapchat.android.crema.Screenshotter.screenshotCurrentActivity(Screenshotter.java:49)
at com.snapchat.android.crema.Screenshotter$1.run(Screenshotter.java:33)
at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:2092)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
INSTRUMENTATION_RESULT: shortMsg=Process crashed.
INSTRUMENTATION_CODE: 0
时,我的某些视图元素无法隐藏,当我将其设置为Gone
时,其他人不会显示。
在此示例中,cmdCallMe不会隐藏,cmdOk和cmdCancel也不会出现。其他元素都按预期运行。
(来源略有缩短)
活动代码:
Visible
AXML:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.p2);
titleStatusView = FindViewById<TextView>(Resource.Id.lblP2Status);
outputTextView = FindViewById<TextView>(Resource.Id.lblP2Timer);
lblConfirm = FindViewById<TextView>(Resource.Id.lblP2Confirm);
cmdP2Update = FindViewById<Button>(Resource.Id.cmdP2Update);
cmdP2Arrived = FindViewById<Button>(Resource.Id.cmdP2Arrived);
cmdP2SelfDeployed = FindViewById<Button>(Resource.Id.cmdP2SelfDeployed);
cmdP2CallMe = FindViewById<Button>(Resource.Id.cmdP2CallMe);
cmdOk = FindViewById<Button>(Resource.Id.cmdP2CallMe);
cmdCancel = FindViewById<Button>(Resource.Id.cmdP2CallMe);
// hide normal buttons
// these all hide as expected
cmdP2Update.Visibility = ViewStates.Gone;
cmdP2Arrived.Visibility = ViewStates.Gone;
cmdP2SelfDeployed.Visibility = ViewStates.Gone;
// this should hide cmdCallMe but it doesn't change
cmdP2CallMe.Visibility = ViewStates.Gone;
// show confirm elements
// this appears as expected
lblConfirm.Visibility = ViewStates.Visible;
// the following 2 buttons should appear, but don't
cmdOk.Visibility = ViewStates.Visible;
cmdCancel.Visibility = ViewStates.Visible;
当我单步执行时,所有值都按照我的预期分配。我无法解释为什么元素可见性并不能始终反映这一点。
答案 0 :(得分:1)
看看你的代码:
cmdP2CallMe = FindViewById<Button>(Resource.Id.cmdP2CallMe);
cmdOk = FindViewById<Button>(Resource.Id.cmdP2CallMe); <-- reference error here
cmdCancel = FindViewById<Button>(Resource.Id.cmdP2CallMe);<-- reference error here
:)