cook cook
cook cook

Reputation: 305

How to fix swing and util timer conflict?

I had being working on a game assignment and never used the util class. Now I need to use File IO so I need to the Scanner from java.util. But now everytime I run the program, it says "error: reference to Timer is ambiguous, both class java.util.Timer in java.util and class javax.swing.Timer in javax.swing match Timer myTimer; "

What should I do?

Upvotes: 4

Views: 4319

Answers (1)

jackrabbit
jackrabbit

Reputation: 5663

You probably imported java.util.* as well as javax.swing.*. Both contain a Timer class, so the compiler does not know which one you want.

The simplest solution is to add an additional import for javax.swing.Timer at the end of your imports. Even better would be to remove one of the * imports and just import the individual classes you need from that package.

BTW, you probably should separate your loading code into a separate class in the first place.

Upvotes: 9

Related Questions