Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Tim Cooke
Paul Clapham
Liutauras Vilda
Sheriffs:
Junilu Lacar
Rob Spoor
Jeanne Boyarsky
Saloon Keepers:
Stephan van Hulst
Carey Brown
Tim Holloway
Piet Souris
Bartenders:
Forum:
Android
Timer & looper.prepare error
simone giusti
Ranch Hand
Posts: 55
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Suppose you have this class:
package it.rockopera.scsremote; import android.content.Context; import java.util.Timer; import java.util.TimerTask; public class CueTimer extends Thread{ private Context context; private MainActivity main = new MainActivity(); private Timer timer; int elapsed = 0 ; public CueTimer(Context c) { context= c; timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { elapsed+=1000; System.out.println("elapsed: " + String.valueOf(elapsed)); } },0,1000);//Update text every second }
I would like to call this method from another class in this way:
CueTimer cuetimer = new CueTimer(context); cuetimer.start()
here's the error:
Process: it.rockopera.scsremote, PID: 7562 java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() at android.os.Handler.<init>(Handler.java:200) at android.os.Handler.<init>(Handler.java:114) at android.app.Activity.<init>(Activity.java:789) at it.rockopera.scsremote.MainActivity.<init>(MainActivity.java:47) at it.rockopera.scsremote.CueTimer.<init>(CueTimer.java:32) at it.rockopera.scsremote.Client$Read_SCS_MSGs.run(Client.java:477) at java.lang.Thread.run(Thread.java:761)
Thanks !!
Norman Radder
Ranch Hand
Posts: 146
4
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
at it.rockopera.scsremote.MainActivity.<init>(MainActivity.java:47)
What does the code in MainActivity do?
Something about .... going for a swim. With this tiny ad ...
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Can't create handler inside thread that has not called Looper.prepare()
SharedPreferences: extends Activity crashes App
getDatabaseLocked
TimerTask and Schedule
Creating a custom listview with data from databas
More...