使用gnome-java的Java程序无法编译

时间:2011-05-17 11:19:19

标签: java gtk javac gnome

尝试编译这个小型Java程序时,要使用java-gnome中的Notifier类(从最新的bzr分支构建):

import org.gnome.notify;


class Notifier {

public void Main(String[] args) {

        Notification n = new Notification("Test notification", "Blah.", "");
        n.setTimeout(2000);
        n.show();

    }
}

使用以下编译时,我得到以下输出:

$ javac -cp .:/usr/local/share/java/gtk-4.0.jar Notifier.java 

Notifier.java:1: package org.gnome does not exist
import org.gnome.notify;
            ^
Notifier.java:7: cannot find symbol
symbol  : class Notification
location: class Notifier
Notification n = new Notification("Test notification", "Blah.", "");
    ^
Notifier.java:7: cannot find symbol
symbol  : class Notification
location: class Notifier
Notification n = new Notification("Test notification", "Blah.", "");
                         ^
3 errors

/usr/local/share/java/gtk-4.0.jar肯定存在于该位置,并且包含已使用的类。怎么了?非常感谢。

2 个答案:

答案 0 :(得分:5)

也许这只是你问题中的拼写错误,但输入行应该是:

import org.gnome.notify.*;

请注意尾随的星号。

此外,您的main方法应该是静态的。

答案 1 :(得分:3)

即使您关注Rich(完全正确),您的应用程序也无法编译。这里是简约的例子:

import org.gnome.gdk.Event;
import org.gnome.gtk.Gtk;
import org.gnome.gtk.Widget;
import org.gnome.gtk.Window;
import org.gnome.notify.Notification;

public class Main {

    public static void main(String[] args) {

        // gtk init
        Gtk.init(args);

        // create main window
        final Window window = new Window();

        // connect delete event to main window
        window.connect(new Window.DeleteEvent() {
            public boolean onDeleteEvent(Widget source, Event event) {
                Gtk.mainQuit();
                return false;
            }
        });

        // create notification
        Notification notification = new Notification("foo", "bar", "baz", window);

        // show widgets
        window.show();
        notification.show();

        // main loop
        Gtk.main();
    }
}

编译器行:

javac -classpath $CLASSPATH:/usr/local/share/java/gtk-4.0.jar Main.java