I'm trying to create a windows with a counter that should increase one every 2 seconds. Here the code:
MainWindow = function() { var win = Ti.UI.createWindow({ backgroundColor : 'white' }); var showCounterLabel = Titanium.UI.createLabel({ color:'#999', text:'undef', font:{fontSize:20,fontFamily:'Helvetica Neue'}, textAlign:'center', height : '50dp', width : '100dp', }); var updateCounterLabel = function() { setTimeout ('updateCounterLabel()',2000); counter = Ti.App.Properties.getInt('counter',0); Ti.App.Properties.setInt('counter', counter + 1); showCounterLabel.text = Ti.App.Properties.getInt('counter',0); }; var resetCounterButton = Ti.UI.createButton({ title : 'resetCounterButton', height : '50dp', width : '100dp', top: '70dp', }); resetCounterButton.addEventListener('click', function() { Ti.App.Properties.setInt('counter', 0); alert('reset done'); }); setTimeout ('updateCounterLabel();',2000); win.add(showCounterLabel); win.add(resetCounterButton); return win; }; module.exports = MainWindow;Everything is compiled and running for the first 2 seconds, after that my App crashes with this message: >The application xxx (process yyy) has stopped unexpectedly. Please try again>
From the log I get:
E/TiApplication( 649): (KrollRuntimeThread) [1483,1483] Sending event: exception on thread: KrollRuntimeThread msg:java.lang.IncompatibleClassChangeError: interface not implemented; Titanium 2.1.1,2012/07/27 14:01,0fd84a2 E/TiApplication( 649): java.lang.IncompatibleClassChangeError: interface not implemented E/TiApplication( 649): at ti.modules.titanium.TitaniumModule$Timer.run(TitaniumModule.java:156) E/TiApplication( 649): at android.os.Handler.handleCallback(Handler.java:587) E/TiApplication( 649): at android.os.Handler.dispatchMessage(Handler.java:92) E/TiApplication( 649): at android.os.Looper.loop(Looper.java:130) E/TiApplication( 649): at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:104) E/AndroidRuntime( 649): FATAL EXCEPTION: KrollRuntimeThread E/AndroidRuntime( 649): java.lang.IncompatibleClassChangeError: interface not implemented E/AndroidRuntime( 649): at ti.modules.titanium.TitaniumModule$Timer.run(TitaniumModule.java:156) E/AndroidRuntime( 649): at android.os.Handler.handleCallback(Handler.java:587) E/AndroidRuntime( 649): at android.os.Handler.dispatchMessage(Handler.java:92) E/AndroidRuntime( 649): at android.os.Looper.loop(Looper.java:130) E/AndroidRuntime( 649): at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:104) W/ActivityManager( 62): Force finishing activity by.wink/.WinkActivity
1 Answer
I think you want to use setInterval so that it runs repeatedly
Your Answer
Think you can help? Login to answer this question!