Data to graphical interface

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Data to graphical interface

Postby agesino » Mon Jan 28, 2008 2:33 am

I am working with Eclipse SDK 3.3.0 and testing the Window Builder Version 6.5.1

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);
   }
}
agesino
 
Posts: 2
Joined: Mon Jan 28, 2008 1:31 am

Re: Data to graphical interface

Postby Eric Clayberg » Mon Jan 28, 2008 4:56 am

In general, an error message like "java.lang.NullPointerException" does not mean anything without some context. Please include the entire exception in the future.

Fortunately, the problem is clear just by looking at your code. You are trying to set the text of the text widget before it has even been created. Presumably, the full exception would have made that clear as well.

I should also point out that this forum is for help with SWT Designer issues. It is not for general SWT or Java questions. Those should be posted to the appropriate eclipse.org or comp.lang.java newsgroup.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 2 guests