Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix swing and util timer conflict?

Tags:

java

swing

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?

like image 590
cook cook Avatar asked Jan 14 '23 02:01

cook cook


1 Answers

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.

like image 120
jackrabbit Avatar answered Jan 21 '23 12:01

jackrabbit