我是Java的新手,我試圖創建一個相當簡單/基本的WatchService程序。我使用Eclipse和這裏的部分代碼片段顯示出是有問題的行:Java導入處理聲明WatchService
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
@SuppressWarnings("serial")
public class MDMButtons extends JFrame implements WindowListener,ActionListener,Runnable {
JButton b1, b2, b3, b4;
ImageIcon red = new ImageIcon("img/red.gif","Down");
ImageIcon green = new ImageIcon("img/green.png","Up");
JLabel imageRed;
JLabel imageGreen;
// File f = new File("fault.txt");
// File file = new File("%userprofile%\\desktop\\error.txt");
WatchService watcher = FileSystems.getDefault().newWatchService();
public static void main(String[] args) throws IOException {
MDMButtons window = new MDMButtons("MDM Dashboard Beta v1.0");
window.setSize(400,200);
window.setVisible(true);
我有以下錯誤交易的問題:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Unhandled exception type IOException at MDMButtons.(MDMButtons.java:38)
at MDMButtons.main(MDMButtons.java:41)
這似乎處理這條線的後半部分(在「=」後):
WatchService watcher = FileSystems.getDefault().newWatchService();
我認爲這與進口的事,但我在爲我需要做什麼來糾正它的損失。
如果我刪除了導入的靜態行,錯誤消失了,但在程序的後面留下了問題,導致依賴於這些導入的代碼行。
任何和所有幫助表示讚賞!
如果你失望的排名我的問題,請沒有禮貌地告訴我爲什麼,所以我可以糾正它。 – makadus