secondstimer.java (private final Stopwatch stopwatch = new Stopwatch();)

Aug 20, 2014
46
0
0
java: constructor Stopwatch in class com.google.common.base.Stopwatch cannot be applied to given types;
required: com.google.common.base.Ticker
found: no arguments
reason: actual and formal argument lists differ in length



where should i look in intellj??

never had this error

venomite base
 
The error message you're seeing indicates that you're trying to instantiate the Stopwatch class from the Google Guava library without providing the required argument. The constructor for Stopwatch is expecting a parameter of type com.google.common.base.Ticker, but you're trying to create a Stopwatch without any arguments.

Here’s a breakdown of what the error message means:

required: com.google.common.base.Ticker - The constructor of Stopwatch you are trying to call requires an argument of type Ticker.
found: no arguments - You are calling the constructor without any arguments.
reason: actual and formal argument lists differ in length - The number of arguments you provided does not match the number required by the constructor.
To resolve this error, you have a couple of options:

Provide a Ticker when constructing the Stopwatch:
You can provide a Ticker, which is an abstraction for reading the current time. You can either use the system ticker or create a custom one. Here's how you can use the system ticker:

Code:
Stopwatch stopwatch = Stopwatch.createStarted(Ticker.systemTicker());
Use the factory method createStarted() or createUnstarted():
Guava provides factory methods that create a Stopwatch using the system ticker by default. If you do not need to provide a custom ticker, you can use these methods:

Code:
Stopwatch stopwatch = Stopwatch.createStarted();  // Automatically starts the stopwatch
Stopwatch unstartedStopwatch = Stopwatch.createUnstarted();  // Creates a stopwatch that is not started

Either of these solutions will help you instantiate Stopwatch correctly, avoiding the constructor issue. Choose the approach that best fits your needs.
 
you can fix this just by changing the version of java your project requires if its not right it will throw this error
 

Users who are viewing this thread (total: 1, members: 0, guests: 1)

Who read this thread (total members: 1)