Displaying alert with multi line message inside lwuit form

713 views Asked by At

I am getting a strange exception when trying to show Dialog alert on lwuit form.

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)

I used following two pieces of code:

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);

Ref.: Alert pop up with LWUIT

and

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();

If someone could point me to source code of lwuit, it would be most helpful.
I found one project named lwuitfixes on google code that does not have any function 'shouldShowHint' inside TextArea.java and official site https://lwuit-incubator.dev.java.net/ never opens!!!!!!!

1

There are 1 answers

0
vivek.m On
l.setTextEditorEnabled(false);

stops the exception. (got hint by browsing the .class file of jar I am using)

Probably never seen a worse API than this.

To remove the white background of TextArea, I had to override its onPaint and fill the graphics with different color.