运行代码时总是说我尝试对空对象引用调用虚拟方法。
不知道哪里出错了
4条回答 默认 最新
关注
- 你可以看下这个问题的回答https://ask.csdn.net/questions/355752
- 我还给你找了一篇非常好的博客,你可以看看是否有帮助,链接:Android 模块化项目不同模块防止资源重复解决方法
- 除此之外, 这篇博客: android 判断当前系统时间是否在特定的时间的段内 两种方式中的 方式一 :方法过时 不影响使用 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
import android.text.format.Time; /** * 判断当前系统时间是否在指定时间的范围内 * * beginHour 开始小时,例如8 * beginMin 开始小时的分钟数,例如30 * endHour 结束小时,例如 20 * endMin 结束小时的分钟数,例如0 * true表示在范围内, 否则false */ public static boolean isCurrentInTimeScope(int beginHour, int beginMin, int endHour, int endMin){ boolean result = false; final long aDayInMillis = 1000 * 60 * 60 *24; final long currentTimeMillis = System.currentTimeMillis(); Time now = new Time(); now.set(currentTimeMillis); Time startTime = new Time(); startTime.set(currentTimeMillis); startTime.hour = beginHour; startTime.minute = beginMin; Time endTime = new Time(); endTime.set(currentTimeMillis); endTime.hour = endHour; endTime.minute = endMin; if (!startTime.before(endTime)){ startTime.set(startTime.toMillis(true) - aDayInMillis); result = !now.before(startTime) && !now.after(endTime); // startTime <= now <= endTime Time startTimeInThisDay = new Time(); startTimeInThisDay.set(startTime.toMillis(true) + aDayInMillis); if (!now.before(startTimeInThisDay)) { result = true; } }else { //普通情况(比如 8:00 - 18:00) result = !now.before(startTime) && !now.after(endTime); // startTime <= now <= endTime } return result; }
解决 无用评论 打赏 举报