I have a Timer class and a Test class to test this timer:
package tools;
public class Timer extends Thread
{
public boolean isRunning = true;
private long timeout = 0;
public Timer(long aTimeout)
{
timeout = aTimeout;
}
// Run the Thread
public void run()
{
int i = 1000;
while(i <= timeout)
{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i = i + 1000;
}
isRunning = false;
}
}
And the Test Class:
public class Test
{
public static void main(String[] args)
{
Timer myTimer = new Timer(10000);
myTimer.start();
while(myTimer.isRunning)
{
System.out.println("Running");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
In Eclipse this works well. When I include it to another project on a Solaris Server, I get the following exception:
Exception in thread "main" java.lang.NoSuchMethodError: tools.Timer.<init>(J)V
I googled it but I could not find any answer – why is this not working ? Cheers, Tim.
You’re constructing timer like this:
And your constructor declaration is:
Obvious, isn’t it? You must either construct the timer like
new Timer(1234), or add a parameterless constructor to it.