无法显示 toast 消息

Unable to display toast messages

我已经下载并使用了下面的代码URL

https://github.com/Pmovil/Toast 显示 toast 消息。

最初我收到 NativeToastImpl Not implemented 错误。我已经通过将本机相关代码复制到我的项目中来解决。现在系统抛出运行时异常 "Toast is not supported in this platform."

这是我用来显示 toast 消息的代码。

public class MyApplication {

private Form current;

private static Object context;

public void init(Object context) {
    MyApplication.context = context;
}

public static Object getContext() {
    return context;
}

public void start() {
    if (current != null) {
        current.show();
        return;
    }

    showLoginForm();
}

public void stop() {
    current = Display.getInstance().getCurrent();
}

public void destroy() {
}

private void showLoginForm() {

    Form form = new Form("WelCome ...");

    Button b = new Button(" Login ");

    b.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            Log.p(" Came hgere ");
            Log.p(" ***    " + MyApplication.getContext());
            Toast.makeText(MyApplication.getContext(), "HI", Toast.LENGTH_LONG);
        }
    });
    form.addComponent(b);
    form.show();
}}

我已经使用 Net Beans IDE 进行开发,OS : windows 8.1

请让我知道我在这段代码中做错了

有没有其他方法可以使用代号 one 来显示 toast 消息?

提前致谢

您错过了 Toast 上的 show() 方法。

Toast.makeText(MyApplication.getContext(), "HI", Toast.LENGTH_LONG).show();

请编辑以下代码并在设备中测试 toast。 Toast 在模拟器中不可用。

public void init(Object context) {
   this.context = context;
}

b.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent evt) {
        Log.p(" Came hgere ");

        Toast.makeText(context, "HI", Toast.LENGTH_LONG);
    }
});