Windows Phone 8.1 NullRefrenceException
NickName:Hunter Ask DateTime:2015-05-05T10:42:16

Windows Phone 8.1 NullRefrenceException

I'm Currently Working on a windows 8.1 Application and im trying to set the value of a textblock that is inside of a Pivot Page. When I try to set the value of the text Block I get a weird error about a Null Refrence Exception.

The Code for the XAML is as follows

<TextBlock x:Name="scoreFinal" Text="0" HorizontalAlignment="Left" Margin="235,408,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="34" Width="97" FontSize="32"/>

Im using an event Handler for TextChanged in a textbox to change the value of the TextBlock using the following code

private void score_TextChanged(object sender, TextChangedEventArgs e)
    {
        int totalPar=38;
        int actual=0;


        // actual = int.Parse(score1.Text) + int.Parse(score2.Text) + int.Parse(score3.Text) + int.Parse(score4.Text) + int.Parse(score5.Text) + int.Parse(score6.Text) + int.Parse(score7.Text) + int.Parse(score8.Text) + int.Parse(score9.Text);
        if (actual < totalPar)
        {


            scoreFinal.Text = ("-" + (totalPar - actual));

        }

When I run the page it loads fine and I have values on all my text boxes to be 0

but when i run this and edit text I get the following error

enter image description here

Anyone got a clue?

Copyright Notice:Content Author:「Hunter」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30043384/windows-phone-8-1-nullrefrenceexception

Answers
Null Pointer 2015-05-05T05:18:33

There is a chance for scoreFinal control is not initialized when score_TextChanged event fired .\n\nTry to hookup TextChanged in page loaded event . \n\n void YourPage_Loaded(object sender, RoutedEventArgs e)\n {\n score2.TextChanged+=score_TextChanged;\n\n }\n\n\nAlso don't forget to remove the event handler from XAML.",


More about “Windows Phone 8.1 NullRefrenceException” related questions

Windows Phone 8.1 vs Windows Phone Silverlight 8.1 - is there missing documentation on MSDN?

I'm attempting to port some .NET code to a Windows Phone 8.1 (not Silverlight) library and have been banging my head against the wall for a while now trying to understand why System.Net.IPAddress w...

Show Detail

Windows Phone 8.1 NullRefrenceException

I'm Currently Working on a windows 8.1 Application and im trying to set the value of a textblock that is inside of a Pivot Page. When I try to set the value of the text Block I get a weird error ab...

Show Detail

Windows Phone 8.1 API

Is there Windows Phone 8.1 API to refer? This is because I want to develop the Windows Phone 8.1 application, but I don't know where to refer the API, since the Windows Phone 8.1 an 8 have a big

Show Detail

Windows 8.1 phone emulator in Windows 8.1 VM?

I connect to a Windows 8.1 Pro VM through Hyper-V running on Windows Server 2008. It looks like in order to run the Windows 8.1 phone emulator, you need to be running Windows 8.1 Pro that is capab...

Show Detail

Charts on Windows Phone 8.1

I'm developing a Windows Phone 8.1 app and I have to draw a chart (line chart). I know there is the WinRT XAML Toolkit but it seems not working for WP8.1 but only for Windows 8.1 apps, like many ot...

Show Detail

Difference between Windows Phone Silverlight 8.1 and Windows Phone 8.1 development

I am working on Windows Phone development. For that I installed required SDK. I do create new project with Windows Phone 8.1, but gradually found that it don't support WCF service as we can not add

Show Detail

BingMapsTask on Windows Phone 8.1

On Windows Phone 8, we call phone's Bing map app with c# using BingMapsTask . But Windows Phone 8.1, BingMapsTask won't work? How to call Bing Maps on Windows Phone 8.1? Can anybody help?

Show Detail

Upgrading from Windows Phone 8 project to Windows Phone 8.1

Are there any equivalent for Windows::Phone::Input::Interop and Windows::Phone::Networking::Voip namespaces in Windows phone 8.1. These are supported in Windows Phone 8 and Windows phone silverligh...

Show Detail

OpenCV on Windows Phone 8.1

How I can use OpenCV on Windows Phone 8.1 Universal in C#? I saw EmguCV but he has only commercial license for Windows Phone. Is possible other way to use OpenCV in C# on Windows Phone 8.1?

Show Detail

Make a phone call in Windows Phone 8.1

I'm writing a Universal App for Windows 8.1 / Windows Phone 8.1 that at some point displays a list of phone numbers. What I would like to do is allow the user to press one of these numbers and have...

Show Detail