[mono-android] I'm just not getting this - why is it a null reference?

Tomasz Cielecki tomasz at ostebaronen.dk
Mon Nov 21 03:43:13 EST 2011


Have you set the context before? It could seem like editText is null
because FindViewById might not be able to locate it.

Try making a sanity check before like:

if (editText != null && editText == "")
{
//should reach here now if everything is ok
}

On Mon, Nov 21, 2011 at 12:13 AM, Paul F. Johnson
<paul at all-the-johnsons.co.uk> wrote:
> Hi,
>
> I have an EditText widget on a tab which has the value 21 in it.
>
> I then try and retrieve the data using the following and it gives me a
> null reference...
>
> EditText editText = FindViewById<EditText>(Resource.Id.tempSurround);
> if (editText.Text == "")
> {
> // fail
> }
>
> The attempt to get the data is called from a button on the second tab.
>
> What is going wrong? I don't have any events set on the first tab, but
> the data is there (I can flick between tabs and the data persists)
>
> Paul
> --
> Vertraue mir, ich weiss, was ich mache...
>
> _______________________________________________
> Monodroid mailing list
> Monodroid at lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>



-- 
Med Venlig Hilsen / With Best Regards
Tomasz Cielecki
http://ostebaronen.dk


More information about the Monodroid mailing list