【发布时间】:2014-04-29 12:12:21
【问题描述】:
我正在尝试在 Titanium 开发的 Android 应用中创建一个标签,该标签会根据我的输入(从当前日期到 2014 年 5 月 30 日)自动更新剩余时间。我使用 JavaScript 创建了以下倒计时函数:
var current = 'Today is the day!';
var montharray = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
function countdown(yr,m,d){
theyear = yr;
themonth = m;
theday = d;
var today = new Date();
var todayy = today.getYear();
var todaym = today.getMonth();
var todayd = today.getDate();
var todayh = today.getHours();
var todaymin = today.getMinutes();
var todaysec = today.getSeconds();
var todaystring = montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
futurestring = montharray[m-1]+" "+d+", "+yr;
dd = Date.parse(futurestring) - Date.parse(todaystring);
dday = Math.floor(dd/(60*60*1000*24)*1);
dhour = Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
dmin = Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
dsec = Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
if (dday==0 && dhour==0 && dmin==0 && dsec==1){
homeLabel6.text = current;
return;
} else {
homeLabel6.text = dday + 'd:'+ dhour + 'h:' + dmin + 'm:' + dsec + 's';
setTimeout('countdown(theyear,themonth,theday)',1000);
}
}
countdown(2014,05,30);
不幸的是,当我在手机上构建应用程序时,我收到以下错误:
[ERROR] : TiApplication: (KrollRuntimeThread) [821,821] Sending event: exception on thread: KrollRuntimeThread msg:java.lang.IncompatibleClassChangeError: interface not implemented; Titanium 3.2.2,2014/03/05 12:22,96e9a07
[ERROR] : TiApplication: java.lang.IncompatibleClassChangeError: interface not implemented
[ERROR] : TiApplication: at ti.modules.titanium.TitaniumModule$Timer.run(TitaniumModule.java:152)
[ERROR] : TiApplication: at android.os.Handler.handleCallback(Handler.java:615)
[ERROR] : TiApplication: at android.os.Handler.dispatchMessage(Handler.java:92)
[ERROR] : TiApplication: at android.os.Looper.loop(Looper.java:137)
[ERROR] : TiApplication: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
如果有人可以向我解释不兼容的地方在哪里以便使这项工作正常进行,那就太好了。我只想要一个标签显示这个没有开始/停止按钮或类似的东西。就像上面在代码 sn-p 中提到的那样,我想要信息的标签被称为:homeLabel6。我也尝试了其他选项,但似乎没有一个适合我的需要。
【问题讨论】:
标签: javascript android datetime titanium titanium-mobile