我在XAML TextBlock中有名称StpTextBlock,在按钮中有名称btnPedometra。

同样在代码中如下:

它还返回了这个例外:

发布于 2017-04-05 15:24:38
局部变量
Pedometer readings从await Pedometer.GetdefaultAsync()分配后仍然为空
readings.Interval = 120;抛出异常,因为readings为空
您需要了解为什么Pedometer.GetdefaultAsync()返回null。
发布于 2017-05-03 08:48:24
正如@rudolf的回答所说,您得到了NullReferenceException,因为Pedometer.GetdefaultAsync()返回的readings是null。
Pedometer.GetdefaultAsync()返回表示默认传感器的计步器对象。如果没有计步器传感器,返回值将为空。因此,在使用计步器时,请确保您的设备有计步器传感器。在代码中,通过确定Pedometer.GetdefaultAsync()的返回值是否为null来检查这一点。
var readings= await Pedometer.GetDefaultAsync();
if (null == readings)
{
MessageDialog showDialog = new MessageDialog("No pedometer available");
await showDialog.ShowAsync();
}
else
{
readings.ReportInterval = readings.MinimumReportInterval;
readings.ReadingChanged += Readings_ReadingChanged;
}有关更多信息,请参考官方的计步器样品 on GitHub。
https://stackoverflow.com/questions/43233418
复制相似问题