我是Windows应用程序开发的新手。我正在尝试使用x64平台在本地计算机上执行解决方案。但是每当我执行Buttom_Click事件时,我都会收到此异常
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
在App.gics文件中。
当调试器点击下面的变量“ icon”时,我得到了这个异常
private async void Button_Click(object sender, RoutedEventArgs e)
{
RootObject myWeather =
await OpenWeatherMapProxy.GetWeather(20.0,30.0);
string icon = String.Format("ms-appx:///Assets/Weather/{0}.png", myWeather.weather[0].icon);
ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute));
ResultTextBlock.Text = myWeather.name + " - " + ((int)myWeather.main.temp).ToString() + " - " + myWeather.weather[0].description;
}
如果有人可以解释如何摆脱此异常以及什么是App.gics文件,这将很有帮助。
App.g.i.cs
是自动生成的文件,由于无法在代码中正确处理异常,因此该文件在该位置处中断。
private async void Button_Click(object sender, RoutedEventArgs e)
{
try{
RootObject myWeather =
await OpenWeatherMapProxy.GetWeather(20.0,30.0);
string icon = String.Format("ms-appx:///Assets/Weather/{0}.png", myWeather.weather[0].icon);
ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute));
ResultTextBlock.Text = myWeather.name + " - " + ((int)myWeather.main.temp).ToString() + " - " + myWeather.weather[0].description;
}
catch(Exception ex)
{
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
}
在应用程序运行时转到“输出”窗口,并仔细查看异常详细信息,您可能会找到答案。
最有可能是由于无法获取数据而导致异常myWeather
或myWeather.weather[0]
为null OpenWeatherMapProxy.GetWeather
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句