尝试在lwuit表单上显示Dialog警告时,我遇到一个奇怪的异常。
java.lang.NullPointerException
at com.sun.lwuit.TextArea.shouldShowHint(+21)
at com.sun.lwuit.TextArea.calcPreferredSize(+4)
at com.sun.lwuit.Component.preferredSize(+63)
at com.sun.lwuit.Component.getPreferredSize(+4)
at com.sun.lwuit.Component.getPreferredW(+4)
at com.sun.lwuit.layouts.FlowLayout.layoutContainer(+139)
at com.sun.lwuit.Container.doLayout(+8)
at com.sun.lwuit.Container.layoutContainer(+16)
at com.sun.lwuit.Container.doLayout(+40)
at com.sun.lwuit.Container.layoutContainer(+16)
at com.sun.lwuit.Container.doLayout(+40)
at com.sun.lwuit.Container.layoutContainer(+16)
at com.sun.lwuit.Container.revalidate(+18)
at com.sun.lwuit.Dialog.showPacked(+107)
at com.sun.lwuit.Dialog.showImpl(+76)
at com.sun.lwuit.Dialog.show(+5)
at com.sun.lwuit.Dialog.showDialog(+9)
at com.test.MainView.ShowAlert(+82)
at com.test.MainView.ShowGameOverAlert(+45)
at com.test.MainView.<init>(+209)
at com.test.Main.startApp(+29)
at javax.microedition.midlet.MIDletProxy.startApp(+7)
我使用了以下两段代码:
Dialog validDialog = new Dialog("Alert");
validDialog.setScrollable(false);
validDialog.setIsScrollVisible(false);
validDialog.setTimeout(5000); // set timeout milliseconds
TextArea textArea = new TextArea("...."); //pass the alert text here
textArea.setFocusable(false);
textArea.setIsScrollVisible(false);
validDialog.addComponent(textArea);
validDialog.show(0, 100, 10, 10, true);
和
Dialog d = new Dialog(title);
TextArea l = new TextArea(1, 20);
l.setText(message);
l.setHint("no hint");
l.setSingleLineTextArea(false);
l.setEditable(false);
l.setGrowByContent(true);
d.addComponent(l);
d.setDialogType(Dialog.TYPE_INFO);
d.setDialogPosition(BorderLayout.CENTER);
d.showDialog();
如果有人能指出lwuit的源代码,那将是最有帮助的 我在Google代码中找到了一个名为lwuitfixes的项目,在TextArea.java中没有任何函数'shouldShowHint',官方网站https://lwuit-incubator.dev.java.net/从未打开!!!!!!!
答案 0 :(得分:0)
l.setTextEditorEnabled(false);
停止例外。 (通过浏览我正在使用的jar的.class文件获得提示)
可能从未见过比这更差的API。
要删除TextArea的白色背景,我必须覆盖其onPaint并用不同颜色填充图形。