多くの検索にもかかわらず、おそらく非常に単純な問題に対する答えが見つかりません。
ポップアップウィンドウを作成するメソッドがあります。次に、ポップアップ ウィンドウの XML の TextViews にアクセスして、テキストを変更する必要があります。問題は、textView が null を返すため、一番下で呼び出されるメソッド countDown(); でテキストを設定しようとすると、null ref 例外が発生することです。
これは、フラグメントではなく、アクティビティで実行されています。null 参照例外の原則は理解していますが、ここで何が起こっているのか、またはそれを修正する方法がわかりません。
メソッドのコードは次のとおりです。
public void clockPopup()
{
LayoutInflater inflater = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
View myPopup = inflater.Inflate (Resource.Layout.PopUpClockTimer, null);
offerExpired = FindViewById<TextView> (Resource.Id.offer_expired); //returns null
timerDigit = FindViewById<TextView> (Resource.Id.test_timer); //returns null
PopupWindow popup = new PopupWindow (myPopup, ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent, true);
popup.ShowAtLocation (myPopup, GravityFlags.Center, 0,0);
popup.Update ();
RunOnUiThread (() => {
countDown ();
});
}
アクセスしようとしているTextViewのxmlは次のとおりです
<TextView
android:id="@+id/test_timer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30sp"/>
<TextView
android:id="@+id/offer_expired"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30sp"/>
どんな助けでも感謝します。