运行这行代码时,我收到一个System.NullReferenceException.
// Occurs on this line
if (xDoc.Root.Element("data").Element("forecast").Element("record").Value == "0")
{
tempnow.Text = xDoc.Root.Element("data").Element("forecast").Element("pop").Value;
}
Run Code Online (Sandbox Code Playgroud)
Xdoc定义在类下面,如果这与它有关.
{
public partial class MainPage : PhoneApplicationPage
{
XDocument xDoc;
Run Code Online (Sandbox Code Playgroud)
这是我试图访问的XML文档,并找到"记录"的值.这也是"Xdoc"所代表的文档,其中包含以下信息.
<data>
<status>success</status>
<location>
<city/>
<fullName>39.6N, 0.3W - 6miles SW of El Puerto, SP</fullName>
<localDate>2014-01-30T01:29:23</localDate>
<localEpoch>1391045363</localEpoch>
<locationID>GP202368</locationID>
</location>
<forecast>
<record>0</record>
<utcEpoch>1391040000</utcEpoch>
<utcDate>2014-01-30T00:00:00</utcDate>
<maxTempC>15.4</maxTempC>
<maxTempF>59.7</maxTempF>
<minTempC>5.2</minTempC>
<minTempF>41.3</minTempF>
<fcstDay>1</fcstDay>
<dayLength>10:07</dayLength>
<sunriseHHMMLocal>8:11am</sunriseHHMMLocal>
<sunsetHHMMLocal>6:18pm</sunsetHHMMLocal>
<nightLength/>
<moonriseHHMMLocal/>
<moonsetHHMMLocal/>
<moonphase/>
<moonillum/>
<moonicon/>
<pop>19</pop>
<uv_index>2</uv_index>
<gustC>30</gustC>
<gustF>19</gustF>
<heatindexC>-999.99</heatindexC>
<heatindexF>-999.99</heatindexF>
<icon>partly-cloudy-sm.png</icon>
<iconBase>partly-cloudy</iconBase>
<iconLg>partly-cloudy.png</iconLg>
<prcpC>0</prcpC>
<prcpF>0</prcpF>
<rh>33</rh>
<skyCover>8</skyCover>
<snowC>0</snowC>
<snowF>0</snowF>
<wdir>NW</wdir>
<windchillC>-999.99</windchillC>
<windchillF>-999.99</windchillF> …Run Code Online (Sandbox Code Playgroud) 非常困惑于为什么"c"在我编程改变时不会改变.没什么可说的,可能是一个愚蠢的错误,但无法弄明白......
//declared OUTSIDE of the method.
private string c = "1";
private void expanded(object sender, GestureEventArgs e)
{
if (debug2.Text == "Temp")
{
if (c == "1")
{
c = "2";
((Storyboard)this.Resources["_in"]).Begin();
}
if (c == "2")
{
c = "1";
((Storyboard)this.Resources["_in1"]).Begin();
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个"1 + 1"的字符串.当我对它进行int.Parse时,输出"11".有没有办法让它找到总和?
代码:(设置为IsolatedStorageSettings,即1 + 1字符串)
MessageBox.Show(int.Parse(settings["favoritesnum"].ToString()).ToString());
Run Code Online (Sandbox Code Playgroud)