当我尝试触发registerClick
方法时,应用程序崩溃了。
我将代码提交到此分支https://github.com/jackygrahamez/MayDay/tree/gear-fit
HomeActivity.java
Bundle bundle=getIntent().getExtras();
boolean startedByCUP=false;
if(bundle!=null) {
startedByCUP = bundle.getBoolean("START_BY_CUP");
Log.e(">>>>>>", "START_BY_CUP");
//multiClickEvent.registerClick(System.currentTimeMillis());
multiClickEvent.registerClick(System.currentTimeMillis());
}
MultiClickEvent.java 包com.mayday.md.trigger;
import android.util.Log;
public class MultiClickEvent {
public static final int TIME_INTERVAL = 10000;
private static final int TOTAL_CLICKS = 5;
private Long firstEventTime;
private int clickCount = 0;
public void reset() {
firstEventTime = null;
clickCount = 0;
}
public void registerClick(Long eventTime) {
if (isFirstClick() || notWithinLimit(eventTime)) {
firstEventTime = eventTime;
clickCount = 1;
return;
}
clickCount++;
Log.e(">>>>>>", "MultiClickEvent clickCount = " + clickCount);
}
private boolean notWithinLimit(long current) {
return (current - firstEventTime) > TIME_INTERVAL;
}
private boolean isFirstClick() {
return firstEventTime == null;
}
public boolean isActivated() {
return clickCount >= TOTAL_CLICKS;
}
}
02-07 21:21:52.249 13534-13534/com.mayday.md I/Process﹕ Sending signal. PID: 13534 SIG: 9
02-07 21:21:55.669 13710-13710/com.mayday.md I/PersonaManager﹕ getPersonaService() name persona_policy
02-07 21:21:55.699 13710-13710/com.mayday.md I/PersonaManager﹕ getPersonaService() name persona_policy
02-07 21:21:55.739 13710-13710/com.mayday.md D/skia﹕ GFXPNG PNG bitmap created width:720 height:1280 bitmap id is 270
02-07 21:21:55.749 13710-13710/com.mayday.md I/dalvikvm-heap﹕ Grow heap (frag case) to 28.465MB for 8294416-byte allocation
02-07 21:21:55.769 13710-13710/com.mayday.md D/skia﹕ GFXPNG PNG bitmap created width:28 height:10 bitmap id is 271
02-07 21:21:55.779 13710-13710/com.mayday.md D/skia﹕ GFXPNG PNG bitmap created width:10 height:28 bitmap id is 272
02-07 21:21:55.779 13710-13710/com.mayday.md D/skia﹕ GFXPNG PNG bitmap created width:12 height:12 bitmap id is 273
02-07 21:21:55.789 13710-13710/com.mayday.md D/skia﹕ GFXPNG PNG bitmap created width:96 height:96 bitmap id is 274
02-07 21:21:55.789 13710-13710/com.mayday.md D/skia﹕ GFXPNG PNG bitmap created width:96 height:96 bitmap id is 275
02-07 21:21:55.789 13710-13710/com.mayday.md D/skia﹕ GFXPNG PNG bitmap created width:96 height:96 bitmap id is 276
02-07 21:21:55.799 13710-13710/com.mayday.md D/skia﹕ GFXPNG PNG bitmap created width:96 height:96 bitmap id is 277
02-07 21:21:55.799 13710-13710/com.mayday.md D/AbsListView﹕ Get MotionRecognitionManager
02-07 21:21:55.809 13710-13710/com.mayday.md D/skia﹕ GFXPNG PNG bitmap created width:1 height:1 bitmap id is 278
02-07 21:21:55.809 13710-13710/com.mayday.md E/>>>>>>﹕ START_BY_CUP
02-07 21:21:55.809 13710-13710/com.mayday.md D/AndroidRuntime﹕ Shutting down VM
02-07 21:21:55.809 13710-13710/com.mayday.md W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41742da0)
02-07 21:21:55.809 13710-13710/com.mayday.md E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mayday.md, PID: 13710
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mayday.md/com.mayday.md.HomeActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
at android.app.ActivityThread.access$900(ActivityThread.java:173)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.mayday.md.HomeActivity.onCreate(HomeActivity.java:63)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
at android.app.ActivityThread.access$900(ActivityThread.java:173)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)