[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] Re: java.lang.NullPointerException

It wasn't a programatic selection.  When the first item is added to a tab
folder, Windows makes that tab be selected.  The application did not call
setSelection().

"Joe Smith" <ohcho@xxxxxxxxxx> wrote in message
news:d82fr2$s2i$1@xxxxxxxxxxxxxxxxxxx
>
> "Steve Northover" <steve_northover@xxxxxxxxxx> wrote in message
> news:d81pid$u5s$1@xxxxxxxxxxxxxxxxxxx
> > You are getting selection notification when the first item is added
> > because
> > it is seleted.  You can avoid this by adding the selection listener
after
> > all of the items have been created.  Hope this helps.
>
> Is this rather unusual behavior? This type of behavior makes things
> difficult to handle. As in AWT, all programatic selections should not
> call listeners.
>
> Regards.
>
> >
> > "MP" <pijnmar@xxxxxxx> wrote in message
> > news:32a7b28de53e741fd45aca8ce6469441$1@xxxxxxxxxxxxxxxxxx
> >> I'm afraid a real noob question. Why do I get a null pointer exception
as
> >> soon as I try to run this code snippet.
> >>
> >> public class test implements SelectionListener {
> >>
> >> private TabItem tabItem_4;
> >> private TabItem tabItem_3;
> >> private TabFolder tabFolder_2;
> >> private TabItem tabItem_1;
> >> private TabItem tabItem;
> >> private TabFolder tabFolder;
> >> private Composite rightcomposite;
> >> private Composite leftcomposite;
> >> private SashForm sashForm;
> >> protected Shell shell;
> >>
> >> public static void main(String[] args) {
> >> try {
> >> test window = new test();
> >> window.open();
> >> } catch (Exception e) {
> >> e.printStackTrace();
> >> }
> >> }
> >>
> >> public void open() {
> >> final Display display = Display.getDefault();
> >> createContents();
> >> shell.open();
> >> shell.layout();
> >> while (!shell.isDisposed()) {
> >> if (!display.readAndDispatch())
> >> display.sleep();
> >> }
> >> }
> >>
> >> protected void createContents() {
> >> shell = new Shell();
> >> shell.setLayout(new FillLayout());
> >> shell.setSize(500, 375);
> >> shell.setText("SWT Application");
> >>
> >> sashForm = new SashForm(shell, SWT.NONE);
> >>
> >> leftcomposite = new Composite(sashForm, SWT.NONE);
> >> leftcomposite.setLayout(new FillLayout());
> >>
> >> tabFolder = new TabFolder(leftcomposite, SWT.NONE);
> >> tabFolder.addSelectionListener(this);
> >>
> >> tabItem_1 = new TabItem(tabFolder, SWT.NONE);
> >> tabItem_1.setText("Item1");
> >>
> >> tabItem = new TabItem(tabFolder, SWT.NONE);
> >> tabItem.setText("Item2");
> >>
> >> rightcomposite = new Composite(sashForm, SWT.NONE);
> >> rightcomposite.setLayout(new FillLayout());
> >>
> >> tabFolder_2 = new TabFolder(rightcomposite, SWT.NONE);
> >>
> >> tabItem_3 = new TabItem(tabFolder_2, SWT.NONE);
> >> tabItem_3.setText("ItemA");
> >>
> >> tabItem_4 = new TabItem(tabFolder_2, SWT.NONE);
> >> tabItem_4.setText("ItemB");
> >> sashForm.setWeights(new int[] { 1, 1 });
> >>
> >> tabFolder.setSelection(0);
> >> }
> >> public void widgetSelected(SelectionEvent e) {
> >>
> >>    if (this.tabFolder.getSelectionIndex() == 0) {
> >>       System.out.println("selection index 0");
> >>    tabFolder_2.setVisible(true);
> >> } else {
> >> tabFolder_2.setVisible(false);
> >> System.out.println("selection index 1");
> >> }
> >>
> >> }
> >> public void widgetDefaultSelected(SelectionEvent e) {
> >> }
> >> }
> >>
> >
> >
>
>