我一直在运行2.3.3的HTC Desire Z上编写代码并且工作正常 - 现在我来测试另一台设备(Nexus One运行2.3.4),它崩溃了.这是代码:
if (me == null || sipManager == null || listener == null){
Log.e("OH","NO");
}
sipManager.register(me, 30, listener);
Run Code Online (Sandbox Code Playgroud)
我传递给sipManager.register的东西都不是null(永远不会调用日志),但这是我的堆栈跟踪:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to create service com.myapp.Service: java.lang.NullPointerException
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1955)
at android.app.ActivityThread.access$2500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.net.sip.SipManager.register(SipManager.java:474)
at com.myapp.Service.onCreate(Service.java:159)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1945)
... 10 more
Run Code Online (Sandbox Code Playgroud)
看看Android源代码似乎也没有显示任何明显的东西 - 我传递给它的所有内容在另一台设备上都有效.
两台设备都运行2.3+并且都启用了SIP堆栈:
if (SipManager.isVoipSupported(this) && SipManager.isApiSupported(this)){
Run Code Online (Sandbox Code Playgroud)
编辑:
这是一个复制问题的完整活动: …
我正试图在HealthKit中保存锻炼.这是我的代码:
__weak typeof(self) weakSelf = self;
self.healthStore = [[HKHealthStore alloc] init];
[self.healthStore requestAuthorizationToShareTypes:[NSSet setWithObject:[HKWorkoutType workoutType]] readTypes:nil completion:^(BOOL success, NSError *error) {
if (success){
HKWorkout *workout = [HKWorkout workoutWithActivityType:HKWorkoutActivityTypeRunning startDate:[NSDate dateWithTimeIntervalSinceNow:-3600] endDate:[NSDate date] duration:3600 totalEnergyBurned:[HKQuantity quantityWithUnit:[HKUnit calorieUnit] doubleValue:100.0] totalDistance:[HKQuantity quantityWithUnit:[HKUnit meterUnit] doubleValue:5000.0] metadata:nil];
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf.healthStore saveObject:workout withCompletion:^(BOOL success, NSError *error) {
NSLog(@"Success? %d", success);
if (error){
NSLog(@"Error: %@", error);
}
}];
}
}];
Run Code Online (Sandbox Code Playgroud)
在提示用户许可(和接受)后,此代码创建一个持续1小时的运行活动,燃烧100卡路里并且距离为5000米.
将锻炼保存到HKHealthStore会给出YES的成功值和零错误 - 所以在这一点上,我希望它会存在.
然而,在打开健康应用程序时,我无法找到锻炼,距离或燃烧的卡路里.我错过了什么?