I have a problem with presenting data into a very simple the GUI.
I have built a very small example where I should put data –from my main class- into my GUI done with WB. It is not working and I receive the following error message: “java.lang.NullPointerException”
My main class, “SourceClass.java” is supposed to put the text “Hello world” into the component text of the GUI.
As you can see, I have removed (commented) the “public static void main(String[] args)” in the GUI.JAVA class because I have it into the main class (SourceClass.java).
Please, someone can help me with this?
Thanks a lot in advance.
Alejandro.
--------------------------------------------------------------------------------------------
SourceClass.java
- Code: Select all
package main.GUIdemo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SourceClass {
/** * @param args */
public static void main(String[] args) {
try {
Gui window = new Gui();
window.text.setText("Hello world");
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
}
--------------------------------------------------------------
Gui.java
- Code: Select all
package main.GUIdemo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;
public class Gui {
public Text text;
protected Shell shell;
/**
* Launch the application
* @param args
public static void main(String[] args) {
try {
Gui window = new Gui();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}*/
/**
* Open the window
*/
public void open() {
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
/**
* Create contents of the window
*/
protected void createContents() {
shell = new Shell();
shell.setSize(292, 215);
shell.setText("Gui test");
text = new Text(shell, SWT.BORDER);
text.setBounds(48, 32, 80, 25);
shell.setTabList(new Control[] {text});
//
}
public void set_Text(String s)
{
this.text.setText(s);
}
}