The method setState(Thread.State) in the type tl_grid_rm_05.TL_columnsCommunicator is not applicable for the arguments (tl_grid_rm_05.State)
in
Programming Questions
•
1 year ago
here a sketch where i isolated the problem.
I can use the name State for a class however, if a class extends Thread then it can't take a argument of the class State anymore. There is a enum Thread.State and i think the pre processor of processing get's lost...
If i use:
- void exampleProblem(sketch_121008c.State instance) {
then it works again.
But if i save the sketch under a new name then i have to change it of course.
So is there a faster way around this? (without renaming State).
- SimpleThread thread1;
- SimpleThread thread2;
- State instance;
- void setup() {
- size(200,200);
- thread1 = new SimpleThread(1000,"a");
- thread1.start();
- thread2 = new SimpleThread(1200,"b");
- thread2.start();
- instance = new State();
- thread1.exampleProblem(instance);
- }
- void draw() {
- background(255);
- fill(0);
- int a = thread1.getCount();
- text(a,10,50);
- int b = thread2.getCount();
- text(b,10,150);
- }
- class SimpleThread extends Thread {
- boolean running; // Is the thread running? Yes or no?
- int wait; // How many milliseconds should we wait in between executions?
- String id; // Thread name
- int count; // counter
- // Constructor, create the thread
- // It is not running by default
- SimpleThread (int w, String s) {
- wait = w;
- running = false;
- id = s;
- count = 0;
- }
- int getCount() {
- return count;
- }
- // Overriding "start()"
- void start () {
- // Set running equal to true
- running = true;
- // Print messages
- println("Starting thread (will execute every " + wait + " milliseconds.)");
- // Do whatever start does in Thread, don't forget this!
- super.start();
- }
- // We must implement run, this gets triggered by start()
- void run () {
- while (running && count < 10) {
- println(id + ": " + count);
- count++;
- // Ok, let's wait for however long we should wait
- try {
- sleep((long)(wait));
- } catch (Exception e) {
- }
- }
- System.out.println(id + " thread is done!"); // The thread is done when we get to the end of run()
- }
- // Our method that quits the thread
- void quit() {
- System.out.println("Quitting.");
- running = false; // Setting running to false ends the loop in run()
- // IUn case the thread is waiting. . .
- interrupt();
- }
- void exampleProblem(State instance) {
- println(instance.wtf);
- }
- }
- class State {
- String wtf = "wtf";
- State() {
- }
- }
1