Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Strange NullPointerExcepion
Strange NullPointerExcepion [message #112501] Sat, 15 November 2008 18:25 Go to next message
Maximilian Falkenstein is currently offline Maximilian FalkensteinFriend
Messages: 9
Registered: July 2009
Junior Member
Hi, following situation: I've got an Application. It displays a login
screen, and logs me in. Fine. But then it displays a button. Only a
Shell with a FillLayout and a button with a SelectionListener. I click
on it. Fine. But if I use two of those shells and click on the button of
the first, I get the following:
osgi> 15.11.2008 19:07:32 org.mortbay.http.HttpServer doStart
INFO: Version Jetty/5.1.x
15.11.2008 19:07:32 org.mortbay.util.Container start
INFO: Started
org.eclipse.equinox.http.jetty.internal.Servlet25Handler@5c1ae90c
15.11.2008 19:07:32 org.mortbay.util.Container start
INFO: Started HttpContext[/,/]
15.11.2008 19:07:32 org.mortbay.http.SocketListener start
INFO: Started SocketListener on 0.0.0.0:14696
15.11.2008 19:07:32 org.mortbay.util.Container start
INFO: Started org.mortbay.http.HttpServer@67a5a19
Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
[1p9hdi55uxb8f],5,main]
Selected
SelectionEvent{Button {Login} data=null item=null detail=0 x=0 y=0
width=0 height=0 text=null doit=true}
Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
[1p9hdi55uxb8f],5,main]
Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
[1p9hdi55uxb8f],5,main]
Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
[1p9hdi55uxb8f],5,main]
java.lang.NullPointerException
at org.eclipse.rwt.internal.events.Event.getEventAdapter(Event. java:35)
at org.eclipse.rwt.internal.events.Event.processEvent(Event.jav a:39)
at org.eclipse.swt.events.TypedEvent.processEvent(TypedEvent.ja va:115)
at org.eclipse.swt.events.TypedEvent.executeNext(TypedEvent.jav a:155)
at
org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.readAndDispa tch(RWTLifeCycle.java:241)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :682)
at mpw_main.Application.createUI(Application.java:23)
at
org.eclipse.rwt.internal.lifecycle.EntryPointManager.createU I(EntryPointManager.java:92)
at
org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWT LifeCycle.java:228)
at
org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadCont roller.run(RWTLifeCycle.java:116)
at java.lang.Thread.run(Thread.java:619)
15.11.2008 19:08:01 org.mortbay.jetty.servlet.ServletHandler handle
SCHWERWIEGEND: /mpw?nocache=1226772481178:
org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:1977)
at org.eclipse.swt.SWT.error(SWT.java:1897)
at org.eclipse.swt.SWT.error(SWT.java:1868)
at org.eclipse.swt.widgets.Widget.error(Widget.java:788)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:718)
at org.eclipse.swt.widgets.Composite.getChildren(Composite.java :105)
at
org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:49)
at org.eclipse.rwt.lifecycle.WidgetUtil.find(WidgetUtil.java:19 7)
at
org.eclipse.swt.internal.widgets.displaykit.DisplayLCA.readF ocusControl(DisplayLCA.java:566)
at
org.eclipse.swt.internal.widgets.displaykit.DisplayLCA.readD ata(DisplayLCA.java:337)
at org.eclipse.rwt.internal.lifecycle.ReadData.execute(ReadData .java:26)
at
org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.continueLife Cycle(RWTLifeCycle.java:206)
at
org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadCont roller.run(RWTLifeCycle.java:115)
at java.lang.Thread.run(Thread.java:619)

If I click on the second button, it works! As you can see in the lines
starting with Thread..., everything is created from the UI thread.
Hopefully,

Maximilian




Relevant snippets:

Application.java:

public int createUI() {
Display display = new Display();
System.out.print(Thread.currentThread().toString());
System.out.print(", ");
System.out.println(display.getThread().toString());
new Ui(display).showMainScreen();
try{
while (!Thread.currentThread().isInterrupted()) {
if (!display.readAndDispatch ()) display.sleep ();
}
} catch(Exception e){
//Nicht gut...
e.printStackTrace();
}
return 0;
}

Ui.java:

public void showMainScreen(){
System.out.print(Thread.currentThread().toString());
System.out.print(", ");
System.out.println(display.getThread().toString());
display.asyncExec(new Runnable(){
public void run() {
MessageDialog.showMessage(display, "Erfolgreich eingeloggt!");
IconManager im = new IconManager();
new AboutIcon().draw(display, dbcon, dbcon.getUserType());
new LogoutIcon().draw(display, dbcon, dbcon.getUserType());
}
});
}


Icon.java:

public abstract class Icon implements SelectionListener, MouseListener{
protected Image icon;
protected int width,height,x,y,id;
protected String tooltip;
protected Shell s;
protected DBCon dbcon;
protected Display d;

public Icon(){
initalize();
}

/**
* In dieser Methode werden die Initalisierungen
* durchgeführt: Laden des Bildes und laden der Koordinaten
* */
protected abstract void initalize();

/**
* Mit dieser Methode wird geprüft, ob der Benutzer
* das Icon überhaupt sehen/ankilcken darf
* */
public abstract boolean hasPermission(int user_type);

/**
* Mit dieser Methode wird das Icon gezeichnet
* */
public void draw(Display d, DBCon dbcon, int user_type){
System.out.print(Thread.currentThread().toString());
System.out.print(", ");
System.out.println(d.getThread().toString());
if(hasPermission(user_type)){
s = new Shell(d, SWT.NO_TRIM);
s.setBackground(d.getSystemColor(SWT.COLOR_WHITE));
this.dbcon = dbcon;
this.d = d;
s.setData(WidgetUtil.CUSTOM_VARIANT, "Icon");
s.setLayout(new FillLayout());

Button b = new Button(s, SWT.FLAT);
b.setBackground(d.getSystemColor(SWT.COLOR_WHITE));
b.setImage(icon);
b.setToolTipText(tooltip);
b.addSelectionListener(this);
b.addMouseListener(this);
b.setData(WidgetUtil.CUSTOM_VARIANT, "Icon");

s.setSize(width, height);
Point p = dbcon.getPos(id);
if(p != null)
s.setLocation(p.x, p.y);
else
s.setLocation(x, y);
s.setVisible(true);
}
}

public void mouseDoubleClick(MouseEvent e) {
}

public void mouseDown(MouseEvent e) {
}

public void widgetDefaultSelected(SelectionEvent e) {
}

public void mouseUp(MouseEvent e) {
if(e.button == 2){
s.setLocation(e.x, e.y);
if(!dbcon.setPos(new Point(e.x, e.y), id))
MessageDialog.showError(d, "Konnte die Position des Icons nicht speichern!");
}
}
}

LogoutIcon.java:

package mpw_main.ui;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.eclipse.rwt.RWT;
import org.eclipse.rwt.graphics.Graphics;
import org.eclipse.swt.events.SelectionEvent;

public class LogoutIcon extends Icon {

public boolean hasPermission(int user_type) {
return true;
}

protected void initalize() {
icon = Graphics.getImage("images/icon-logout.png", getClass().getClassLoader());
x = 128;
y = 300;
width = 70;
height = 70;
tooltip = "Logout";
id = 1;
}

public void widgetSelected(SelectionEvent f) {
System.out.print(Thread.currentThread().toString());
System.out.print(", ");
System.out.println(d.getThread().toString());
dbcon.logout();
try{
RWT.getResponse().sendRedirect("http://www.google.de");
} catch(Exception e){
Logger.getLogger("mpw").log(Level.SEVERE, "Couldn't kick the user", e);
}
//TODO: Kick the user
}

}


AboutIcon.java:

public class AboutIcon extends Icon {

public boolean hasPermission(int user_type) {
return true;
}

protected void initalize() {
icon = Graphics.getImage("images/icon-about.png", getClass().getClassLoader());
x = 0;
y = 300;
width = 70;
height = 70;
tooltip = "Über";
id = 0;
}

public void widgetSelected(SelectionEvent e) {
/*d.syncExec(new Runnable(){
public void run(){
new AboutDialog(d);
}
});*/
System.out.print(Thread.currentThread().toString());
System.out.print(", ");
System.out.println(d.getThread().toString());
}
}
Re: Strange NullPointerExcepion [message #112581 is a reply to message #112501] Mon, 17 November 2008 17:03 Go to previous messageGo to next message
Adam is currently offline AdamFriend
Messages: 25
Registered: July 2009
Junior Member
Are you using Singletons? If not, look further down this forum for the
Innoopract Webinar on RAP, it discusses Singletons in more detail, and I
am inclined to believe that is the cause of your error.
Re: Strange NullPointerExcepion [message #112664 is a reply to message #112581] Tue, 18 November 2008 17:46 Go to previous messageGo to next message
Maximilian Falkenstein is currently offline Maximilian FalkensteinFriend
Messages: 9
Registered: July 2009
Junior Member
Well, my MANIFEST.MF looks like this:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Mpw_main Plug-in
Bundle-SymbolicName: mpw_main;singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: mpw_main.Activator
Require-Bundle: org.eclipse.rap.ui;bundle-version="1.1.1",
org.eclipse.rap.ui.forms;bundle-version="1.1.1"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: javax.servlet;version="2.4.0",
javax.servlet.http;version="2.4.0"
Bundle-ClassPath: mysql-connector-java-5.1.7-bin.jar,
.,
src/images/,
src/

If I set singleton to false, I get a build error.
What are singletons?
Re: Strange NullPointerExcepion [message #112677 is a reply to message #112664] Tue, 18 November 2008 18:40 Go to previous messageGo to next message
Adam is currently offline AdamFriend
Messages: 25
Registered: July 2009
Junior Member
Singletons help you create one instance of a class. The Webinar further
down this forum provides a template for you to setup singletons. You may
have them enabled in your MANIFEST, but that doesn't mean they are
implemented. Check out the webinar and let us know if you are still having
problems.
Re: Strange NullPointerExcepion [message #112689 is a reply to message #112677] Tue, 18 November 2008 19:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: evolanakis.innoopract.com

Hi Max,

here's the explanation from the OSGi spec:

"The framework must recognize the following directives for the
Bundle-SymbolicName header:

* singleton -- Indicates that the bundle can only have a single version
resolved. A value of true indicates that the bundle is a singleton
bundle. The default value is false. The Framework must resolve at most
one bundle when multiple versions of a singleton bundle with the same
symbolic name are installed. Singleton bundles do not affect the
"
-- OSGi Service Platform Core Specification, R4 V4.0.1, Para 3.5.2,
www.osgi.org

What is means is that though you may INSTALL several bundles with the
same id and different versions, only one bundle may be in the RESOLVED
state (i.e. ready to run). This is mandatory for bundles that contribute
to the UI using extension points (otherwise, for example, you would see
two contributions of the same perspective).

Adam, this is somewhat different than the singletons / session
singletons mentioned in the webinar.

Kind regards,
Elias.

Adam wrote:
> Singletons help you create one instance of a class. The Webinar further
> down this forum provides a template for you to setup singletons. You may
> have them enabled in your MANIFEST, but that doesn't mean they are
> implemented. Check out the webinar and let us know if you are still
> having problems.
>


--
---
Elias Volanakis
Innoopract, Inc.
http://www.innoopract.com
Re: Strange NullPointerExcepion [message #112832 is a reply to message #112501] Wed, 19 November 2008 20:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rherrmann.innoopract.com

Maximilian,

this might be a bug. If you can provide a self-contained
project/snippet, feel free to open a bugzilla.

Cheers,
Rüdiger


Maximilian Falkenstein wrote:
> Hi, following situation: I've got an Application. It displays a login
> screen, and logs me in. Fine. But then it displays a button. Only a
> Shell with a FillLayout and a button with a SelectionListener. I click
> on it. Fine. But if I use two of those shells and click on the button of
> the first, I get the following:
> osgi> 15.11.2008 19:07:32 org.mortbay.http.HttpServer doStart
> INFO: Version Jetty/5.1.x
> 15.11.2008 19:07:32 org.mortbay.util.Container start
> INFO: Started
> org.eclipse.equinox.http.jetty.internal.Servlet25Handler@5c1ae90c
> 15.11.2008 19:07:32 org.mortbay.util.Container start
> INFO: Started HttpContext[/,/]
> 15.11.2008 19:07:32 org.mortbay.http.SocketListener start
> INFO: Started SocketListener on 0.0.0.0:14696
> 15.11.2008 19:07:32 org.mortbay.util.Container start
> INFO: Started org.mortbay.http.HttpServer@67a5a19
> Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
> [1p9hdi55uxb8f],5,main]
> Selected
> SelectionEvent{Button {Login} data=null item=null detail=0 x=0 y=0
> width=0 height=0 text=null doit=true}
> Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
> [1p9hdi55uxb8f],5,main]
> Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
> [1p9hdi55uxb8f],5,main]
> Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
> [1p9hdi55uxb8f],5,main]
> java.lang.NullPointerException
> at org.eclipse.rwt.internal.events.Event.getEventAdapter(Event. java:35)
> at org.eclipse.rwt.internal.events.Event.processEvent(Event.jav a:39)
> at org.eclipse.swt.events.TypedEvent.processEvent(TypedEvent.ja va:115)
> at org.eclipse.swt.events.TypedEvent.executeNext(TypedEvent.jav a:155)
> at
> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.readAndDispa tch(RWTLifeCycle.java:241)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :682)
> at mpw_main.Application.createUI(Application.java:23)
> at
> org.eclipse.rwt.internal.lifecycle.EntryPointManager.createU I(EntryPointManager.java:92)
> at
> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWT LifeCycle.java:228)
> at
> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadCont roller.run(RWTLifeCycle.java:116)
> at java.lang.Thread.run(Thread.java:619)
> 15.11.2008 19:08:01 org.mortbay.jetty.servlet.ServletHandler handle
> SCHWERWIEGEND: /mpw?nocache=1226772481178:
> org.eclipse.swt.SWTException: Invalid thread access
> at org.eclipse.swt.SWT.error(SWT.java:1977)
> at org.eclipse.swt.SWT.error(SWT.java:1897)
> at org.eclipse.swt.SWT.error(SWT.java:1868)
> at org.eclipse.swt.widgets.Widget.error(Widget.java:788)
> at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:718)
> at org.eclipse.swt.widgets.Composite.getChildren(Composite.java :105)
> at
> org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:49)
> at org.eclipse.rwt.lifecycle.WidgetUtil.find(WidgetUtil.java:19 7)
> at
> org.eclipse.swt.internal.widgets.displaykit.DisplayLCA.readF ocusControl(DisplayLCA.java:566)
> at
> org.eclipse.swt.internal.widgets.displaykit.DisplayLCA.readD ata(DisplayLCA.java:337)
> at org.eclipse.rwt.internal.lifecycle.ReadData.execute(ReadData .java:26)
> at
> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.continueLife Cycle(RWTLifeCycle.java:206)
> at
> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadCont roller.run(RWTLifeCycle.java:115)
> at java.lang.Thread.run(Thread.java:619)
>
> If I click on the second button, it works! As you can see in the lines
> starting with Thread..., everything is created from the UI thread.
> Hopefully,
>
> Maximilian
>
>
>
>
> Relevant snippets:
>
> Application.java:
>
> public int createUI() {
> Display display = new Display();
> System.out.print(Thread.currentThread().toString());
> System.out.print(", ");
> System.out.println(display.getThread().toString());
> new Ui(display).showMainScreen();
> try{
> while (!Thread.currentThread().isInterrupted()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> } catch(Exception e){
> //Nicht gut...
> e.printStackTrace();
> }
> return 0;
> }
>
> Ui.java:
>
> public void showMainScreen(){
> System.out.print(Thread.currentThread().toString());
> System.out.print(", ");
> System.out.println(display.getThread().toString());
> display.asyncExec(new Runnable(){
> public void run() {
> MessageDialog.showMessage(display, "Erfolgreich eingeloggt!");
> IconManager im = new IconManager();
> new AboutIcon().draw(display, dbcon, dbcon.getUserType());
> new LogoutIcon().draw(display, dbcon, dbcon.getUserType());
> }
> });
> }
>
>
> Icon.java:
>
> public abstract class Icon implements SelectionListener, MouseListener{
> protected Image icon;
> protected int width,height,x,y,id;
> protected String tooltip;
> protected Shell s;
> protected DBCon dbcon;
> protected Display d;
>
> public Icon(){
> initalize();
> }
>
> /**
> * In dieser Methode werden die Initalisierungen
> * durchgeführt: Laden des Bildes und laden der Koordinaten
> * */
> protected abstract void initalize();
>
> /**
> * Mit dieser Methode wird geprüft, ob der Benutzer
> * das Icon überhaupt sehen/ankilcken darf
> * */
> public abstract boolean hasPermission(int user_type);
>
> /**
> * Mit dieser Methode wird das Icon gezeichnet
> * */
> public void draw(Display d, DBCon dbcon, int user_type){
> System.out.print(Thread.currentThread().toString());
> System.out.print(", ");
> System.out.println(d.getThread().toString());
> if(hasPermission(user_type)){
> s = new Shell(d, SWT.NO_TRIM);
> s.setBackground(d.getSystemColor(SWT.COLOR_WHITE));
> this.dbcon = dbcon;
> this.d = d;
> s.setData(WidgetUtil.CUSTOM_VARIANT, "Icon");
> s.setLayout(new FillLayout());
>
> Button b = new Button(s, SWT.FLAT);
> b.setBackground(d.getSystemColor(SWT.COLOR_WHITE));
> b.setImage(icon);
> b.setToolTipText(tooltip);
> b.addSelectionListener(this);
> b.addMouseListener(this);
> b.setData(WidgetUtil.CUSTOM_VARIANT, "Icon");
>
> s.setSize(width, height);
> Point p = dbcon.getPos(id);
> if(p != null)
> s.setLocation(p.x, p.y);
> else
> s.setLocation(x, y);
> s.setVisible(true);
> }
> }
>
> public void mouseDoubleClick(MouseEvent e) {
> }
>
> public void mouseDown(MouseEvent e) {
> }
>
> public void widgetDefaultSelected(SelectionEvent e) {
> }
>
> public void mouseUp(MouseEvent e) {
> if(e.button == 2){
> s.setLocation(e.x, e.y);
> if(!dbcon.setPos(new Point(e.x, e.y), id))
> MessageDialog.showError(d, "Konnte die Position des Icons nicht speichern!");
> }
> }
> }
>
> LogoutIcon.java:
>
> package mpw_main.ui;
>
> import java.util.logging.Level;
> import java.util.logging.Logger;
>
> import org.eclipse.rwt.RWT;
> import org.eclipse.rwt.graphics.Graphics;
> import org.eclipse.swt.events.SelectionEvent;
>
> public class LogoutIcon extends Icon {
>
> public boolean hasPermission(int user_type) {
> return true;
> }
>
> protected void initalize() {
> icon = Graphics.getImage("images/icon-logout.png", getClass().getClassLoader());
> x = 128;
> y = 300;
> width = 70;
> height = 70;
> tooltip = "Logout";
> id = 1;
> }
>
> public void widgetSelected(SelectionEvent f) {
> System.out.print(Thread.currentThread().toString());
> System.out.print(", ");
> System.out.println(d.getThread().toString());
> dbcon.logout();
> try{
> RWT.getResponse().sendRedirect("http://www.google.de");
> } catch(Exception e){
> Logger.getLogger("mpw").log(Level.SEVERE, "Couldn't kick the user", e);
> }
> //TODO: Kick the user
> }
>
> }
>
>
> AboutIcon.java:
>
> public class AboutIcon extends Icon {
>
> public boolean hasPermission(int user_type) {
> return true;
> }
>
> protected void initalize() {
> icon = Graphics.getImage("images/icon-about.png", getClass().getClassLoader());
> x = 0;
> y = 300;
> width = 70;
> height = 70;
> tooltip = "Über";
> id = 0;
> }
>
> public void widgetSelected(SelectionEvent e) {
> /*d.syncExec(new Runnable(){
> public void run(){
> new AboutDialog(d);
> }
> });*/
> System.out.print(Thread.currentThread().toString());
> System.out.print(", ");
> System.out.println(d.getThread().toString());
> }
> }
Re: Strange NullPointerExcepion [message #112912 is a reply to message #112832] Thu, 20 November 2008 12:59 Go to previous messageGo to next message
Maximilian Falkenstein is currently offline Maximilian FalkensteinFriend
Messages: 9
Registered: July 2009
Junior Member
Ok. I'll do this this or next evening.

Rüdiger Herrmann schrieb:
> Maximilian,
>
> this might be a bug. If you can provide a self-contained
> project/snippet, feel free to open a bugzilla.
>
> Cheers,
> Rüdiger
>
>
> Maximilian Falkenstein wrote:
>> Hi, following situation: I've got an Application. It displays a login
>> screen, and logs me in. Fine. But then it displays a button. Only a
>> Shell with a FillLayout and a button with a SelectionListener. I click
>> on it. Fine. But if I use two of those shells and click on the button of
>> the first, I get the following:
>> osgi> 15.11.2008 19:07:32 org.mortbay.http.HttpServer doStart
>> INFO: Version Jetty/5.1.x
>> 15.11.2008 19:07:32 org.mortbay.util.Container start
>> INFO: Started
>> org.eclipse.equinox.http.jetty.internal.Servlet25Handler@5c1ae90c
>> 15.11.2008 19:07:32 org.mortbay.util.Container start
>> INFO: Started HttpContext[/,/]
>> 15.11.2008 19:07:32 org.mortbay.http.SocketListener start
>> INFO: Started SocketListener on 0.0.0.0:14696
>> 15.11.2008 19:07:32 org.mortbay.util.Container start
>> INFO: Started org.mortbay.http.HttpServer@67a5a19
>> Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
>> [1p9hdi55uxb8f],5,main]
>> Selected
>> SelectionEvent{Button {Login} data=null item=null detail=0 x=0 y=0
>> width=0 height=0 text=null doit=true}
>> Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
>> [1p9hdi55uxb8f],5,main]
>> Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
>> [1p9hdi55uxb8f],5,main]
>> Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
>> [1p9hdi55uxb8f],5,main]
>> java.lang.NullPointerException
>> at
>> org.eclipse.rwt.internal.events.Event.getEventAdapter(Event. java:35)
>> at org.eclipse.rwt.internal.events.Event.processEvent(Event.jav a:39)
>> at
>> org.eclipse.swt.events.TypedEvent.processEvent(TypedEvent.ja va:115)
>> at org.eclipse.swt.events.TypedEvent.executeNext(TypedEvent.jav a:155)
>> at
>> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.readAndDispa tch(RWTLifeCycle.java:241)
>>
>> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :682)
>> at mpw_main.Application.createUI(Application.java:23)
>> at
>> org.eclipse.rwt.internal.lifecycle.EntryPointManager.createU I(EntryPointManager.java:92)
>>
>> at
>> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWT LifeCycle.java:228)
>>
>> at
>> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadCont roller.run(RWTLifeCycle.java:116)
>>
>> at java.lang.Thread.run(Thread.java:619)
>> 15.11.2008 19:08:01 org.mortbay.jetty.servlet.ServletHandler handle
>> SCHWERWIEGEND: /mpw?nocache=1226772481178:
>> org.eclipse.swt.SWTException: Invalid thread access
>> at org.eclipse.swt.SWT.error(SWT.java:1977)
>> at org.eclipse.swt.SWT.error(SWT.java:1897)
>> at org.eclipse.swt.SWT.error(SWT.java:1868)
>> at org.eclipse.swt.widgets.Widget.error(Widget.java:788)
>> at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:718)
>> at org.eclipse.swt.widgets.Composite.getChildren(Composite.java :105)
>> at
>> org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:49)
>>
>> at org.eclipse.rwt.lifecycle.WidgetUtil.find(WidgetUtil.java:19 7)
>> at
>> org.eclipse.swt.internal.widgets.displaykit.DisplayLCA.readF ocusControl(DisplayLCA.java:566)
>>
>> at
>> org.eclipse.swt.internal.widgets.displaykit.DisplayLCA.readD ata(DisplayLCA.java:337)
>>
>> at
>> org.eclipse.rwt.internal.lifecycle.ReadData.execute(ReadData .java:26)
>> at
>> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.continueLife Cycle(RWTLifeCycle.java:206)
>>
>> at
>> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadCont roller.run(RWTLifeCycle.java:115)
>>
>> at java.lang.Thread.run(Thread.java:619)
>>
>> If I click on the second button, it works! As you can see in the lines
>> starting with Thread..., everything is created from the UI thread.
>> Hopefully,
>>
>> Maximilian
>>
>>
>>
>>
>> Relevant snippets:
>>
>> Application.java:
>>
>> public int createUI() {
>> Display display = new Display();
>> System.out.print(Thread.currentThread().toString());
>> System.out.print(", ");
>> System.out.println(display.getThread().toString());
>> new Ui(display).showMainScreen();
>> try{
>> while (!Thread.currentThread().isInterrupted()) {
>> if (!display.readAndDispatch ()) display.sleep ();
>> }
>> } catch(Exception e){
>> //Nicht gut...
>> e.printStackTrace();
>> }
>> return 0;
>> }
>>
>> Ui.java:
>>
>> public void showMainScreen(){
>> System.out.print(Thread.currentThread().toString());
>> System.out.print(", ");
>> System.out.println(display.getThread().toString());
>> display.asyncExec(new Runnable(){
>> public void run() {
>> MessageDialog.showMessage(display, "Erfolgreich
>> eingeloggt!");
>> IconManager im = new IconManager();
>> new AboutIcon().draw(display, dbcon,
>> dbcon.getUserType());
>> new LogoutIcon().draw(display, dbcon,
>> dbcon.getUserType());
>> }
>> });
>> }
>>
>>
>> Icon.java:
>>
>> public abstract class Icon implements SelectionListener, MouseListener{
>> protected Image icon;
>> protected int width,height,x,y,id;
>> protected String tooltip;
>> protected Shell s;
>> protected DBCon dbcon;
>> protected Display d;
>>
>> public Icon(){
>> initalize();
>> }
>>
>> /**
>> * In dieser Methode werden die Initalisierungen
>> * durchgeführt: Laden des Bildes und laden der Koordinaten
>> * */
>> protected abstract void initalize();
>>
>> /**
>> * Mit dieser Methode wird geprüft, ob der Benutzer
>> * das Icon überhaupt sehen/ankilcken darf
>> * */
>> public abstract boolean hasPermission(int user_type);
>>
>> /**
>> * Mit dieser Methode wird das Icon gezeichnet
>> * */
>> public void draw(Display d, DBCon dbcon, int user_type){
>> System.out.print(Thread.currentThread().toString());
>> System.out.print(", ");
>> System.out.println(d.getThread().toString());
>> if(hasPermission(user_type)){
>> s = new Shell(d, SWT.NO_TRIM);
>> s.setBackground(d.getSystemColor(SWT.COLOR_WHITE));
>> this.dbcon = dbcon;
>> this.d = d;
>> s.setData(WidgetUtil.CUSTOM_VARIANT, "Icon");
>> s.setLayout(new FillLayout());
>>
>> Button b = new Button(s, SWT.FLAT);
>> b.setBackground(d.getSystemColor(SWT.COLOR_WHITE));
>> b.setImage(icon);
>> b.setToolTipText(tooltip);
>> b.addSelectionListener(this);
>> b.addMouseListener(this);
>> b.setData(WidgetUtil.CUSTOM_VARIANT, "Icon");
>>
>> s.setSize(width, height);
>> Point p = dbcon.getPos(id);
>> if(p != null)
>> s.setLocation(p.x, p.y);
>> else
>> s.setLocation(x, y);
>> s.setVisible(true);
>> }
>> }
>>
>> public void mouseDoubleClick(MouseEvent e) {
>> }
>>
>> public void mouseDown(MouseEvent e) {
>> }
>>
>> public void widgetDefaultSelected(SelectionEvent e) {
>> }
>>
>> public void mouseUp(MouseEvent e) {
>> if(e.button == 2){
>> s.setLocation(e.x, e.y);
>> if(!dbcon.setPos(new Point(e.x, e.y), id))
>> MessageDialog.showError(d, "Konnte die Position des
>> Icons nicht speichern!");
>> }
>> }
>> }
>>
>> LogoutIcon.java:
>>
>> package mpw_main.ui;
>>
>> import java.util.logging.Level;
>> import java.util.logging.Logger;
>>
>> import org.eclipse.rwt.RWT;
>> import org.eclipse.rwt.graphics.Graphics;
>> import org.eclipse.swt.events.SelectionEvent;
>>
>> public class LogoutIcon extends Icon {
>>
>> public boolean hasPermission(int user_type) {
>> return true;
>> }
>>
>> protected void initalize() {
>> icon = Graphics.getImage("images/icon-logout.png",
>> getClass().getClassLoader());
>> x = 128;
>> y = 300;
>> width = 70;
>> height = 70;
>> tooltip = "Logout";
>> id = 1;
>> }
>>
>> public void widgetSelected(SelectionEvent f) {
>> System.out.print(Thread.currentThread().toString());
>> System.out.print(", ");
>> System.out.println(d.getThread().toString());
>> dbcon.logout();
>> try{
>> RWT.getResponse().sendRedirect("http://www.google.de");
>> } catch(Exception e){
>> Logger.getLogger("mpw").log(Level.SEVERE, "Couldn't kick
>> the user", e);
>> }
>> //TODO: Kick the user
>> }
>>
>> }
>>
>>
>> AboutIcon.java:
>>
>> public class AboutIcon extends Icon {
>>
>> public boolean hasPermission(int user_type) {
>> return true;
>> }
>>
>> protected void initalize() {
>> icon = Graphics.getImage("images/icon-about.png",
>> getClass().getClassLoader());
>> x = 0;
>> y = 300;
>> width = 70;
>> height = 70;
>> tooltip = "Über";
>> id = 0;
>> }
>>
>> public void widgetSelected(SelectionEvent e) {
>> /*d.syncExec(new Runnable(){
>> public void run(){
>> new AboutDialog(d);
>> }
>> });*/
>> System.out.print(Thread.currentThread().toString());
>> System.out.print(", ");
>> System.out.println(d.getThread().toString());
>> }
>> }
Re: Strange NullPointerExcepion [message #113205 is a reply to message #112912] Mon, 24 November 2008 13:46 Go to previous message
Maximilian Falkenstein is currently offline Maximilian FalkensteinFriend
Messages: 9
Registered: July 2009
Junior Member
https://bugs.eclipse.org/bugs/show_bug.cgi?id=256195

Maximilian Falkenstein schrieb:
> Ok. I'll do this this or next evening.
>
> Rüdiger Herrmann schrieb:
>> Maximilian,
>>
>> this might be a bug. If you can provide a self-contained
>> project/snippet, feel free to open a bugzilla.
>>
>> Cheers,
>> Rüdiger
>>
>>
>> Maximilian Falkenstein wrote:
>>> Hi, following situation: I've got an Application. It displays a login
>>> screen, and logs me in. Fine. But then it displays a button. Only a
>>> Shell with a FillLayout and a button with a SelectionListener. I click
>>> on it. Fine. But if I use two of those shells and click on the button of
>>> the first, I get the following:
>>> osgi> 15.11.2008 19:07:32 org.mortbay.http.HttpServer doStart
>>> INFO: Version Jetty/5.1.x
>>> 15.11.2008 19:07:32 org.mortbay.util.Container start
>>> INFO: Started
>>> org.eclipse.equinox.http.jetty.internal.Servlet25Handler@5c1ae90c
>>> 15.11.2008 19:07:32 org.mortbay.util.Container start
>>> INFO: Started HttpContext[/,/]
>>> 15.11.2008 19:07:32 org.mortbay.http.SocketListener start
>>> INFO: Started SocketListener on 0.0.0.0:14696
>>> 15.11.2008 19:07:32 org.mortbay.util.Container start
>>> INFO: Started org.mortbay.http.HttpServer@67a5a19
>>> Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
>>> [1p9hdi55uxb8f],5,main]
>>> Selected
>>> SelectionEvent{Button {Login} data=null item=null detail=0 x=0 y=0
>>> width=0 height=0 text=null doit=true}
>>> Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
>>> [1p9hdi55uxb8f],5,main]
>>> Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
>>> [1p9hdi55uxb8f],5,main]
>>> Thread[UIThread [1p9hdi55uxb8f],5,main], Thread[UIThread
>>> [1p9hdi55uxb8f],5,main]
>>> java.lang.NullPointerException
>>> at
>>> org.eclipse.rwt.internal.events.Event.getEventAdapter(Event. java:35)
>>> at org.eclipse.rwt.internal.events.Event.processEvent(Event.jav a:39)
>>> at
>>> org.eclipse.swt.events.TypedEvent.processEvent(TypedEvent.ja va:115)
>>> at org.eclipse.swt.events.TypedEvent.executeNext(TypedEvent.jav a:155)
>>> at
>>> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.readAndDispa tch(RWTLifeCycle.java:241)
>>>
>>> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :682)
>>> at mpw_main.Application.createUI(Application.java:23)
>>> at
>>> org.eclipse.rwt.internal.lifecycle.EntryPointManager.createU I(EntryPointManager.java:92)
>>>
>>> at
>>> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWT LifeCycle.java:228)
>>>
>>> at
>>> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadCont roller.run(RWTLifeCycle.java:116)
>>>
>>> at java.lang.Thread.run(Thread.java:619)
>>> 15.11.2008 19:08:01 org.mortbay.jetty.servlet.ServletHandler handle
>>> SCHWERWIEGEND: /mpw?nocache=1226772481178:
>>> org.eclipse.swt.SWTException: Invalid thread access
>>> at org.eclipse.swt.SWT.error(SWT.java:1977)
>>> at org.eclipse.swt.SWT.error(SWT.java:1897)
>>> at org.eclipse.swt.SWT.error(SWT.java:1868)
>>> at org.eclipse.swt.widgets.Widget.error(Widget.java:788)
>>> at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:718)
>>> at org.eclipse.swt.widgets.Composite.getChildren(Composite.java :105)
>>> at
>>> org.eclipse.swt.internal.widgets.WidgetTreeVisitor.accept(Wi dgetTreeVisitor.java:49)
>>>
>>> at org.eclipse.rwt.lifecycle.WidgetUtil.find(WidgetUtil.java:19 7)
>>> at
>>> org.eclipse.swt.internal.widgets.displaykit.DisplayLCA.readF ocusControl(DisplayLCA.java:566)
>>>
>>> at
>>> org.eclipse.swt.internal.widgets.displaykit.DisplayLCA.readD ata(DisplayLCA.java:337)
>>>
>>> at
>>> org.eclipse.rwt.internal.lifecycle.ReadData.execute(ReadData .java:26)
>>> at
>>> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.continueLife Cycle(RWTLifeCycle.java:206)
>>>
>>> at
>>> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadCont roller.run(RWTLifeCycle.java:115)
>>>
>>> at java.lang.Thread.run(Thread.java:619)
>>>
>>> If I click on the second button, it works! As you can see in the lines
>>> starting with Thread..., everything is created from the UI thread.
>>> Hopefully,
>>>
>>> Maximilian
>>>
>>>
>>>
>>>
>>> Relevant snippets:
>>>
>>> Application.java:
>>>
>>> public int createUI() {
>>> Display display = new Display();
>>> System.out.print(Thread.currentThread().toString());
>>> System.out.print(", ");
>>> System.out.println(display.getThread().toString());
>>> new Ui(display).showMainScreen();
>>> try{
>>> while (!Thread.currentThread().isInterrupted()) {
>>> if (!display.readAndDispatch ()) display.sleep ();
>>> }
>>> } catch(Exception e){
>>> //Nicht gut...
>>> e.printStackTrace();
>>> }
>>> return 0;
>>> }
>>>
>>> Ui.java:
>>>
>>> public void showMainScreen(){
>>> System.out.print(Thread.currentThread().toString());
>>> System.out.print(", ");
>>> System.out.println(display.getThread().toString());
>>> display.asyncExec(new Runnable(){
>>> public void run() {
>>> MessageDialog.showMessage(display, "Erfolgreich
>>> eingeloggt!");
>>> IconManager im = new IconManager();
>>> new AboutIcon().draw(display, dbcon,
>>> dbcon.getUserType());
>>> new LogoutIcon().draw(display, dbcon,
>>> dbcon.getUserType());
>>> }
>>> });
>>> }
>>>
>>>
>>> Icon.java:
>>>
>>> public abstract class Icon implements SelectionListener, MouseListener{
>>> protected Image icon;
>>> protected int width,height,x,y,id;
>>> protected String tooltip;
>>> protected Shell s;
>>> protected DBCon dbcon;
>>> protected Display d;
>>>
>>> public Icon(){
>>> initalize();
>>> }
>>>
>>> /**
>>> * In dieser Methode werden die Initalisierungen
>>> * durchgeführt: Laden des Bildes und laden der Koordinaten
>>> * */
>>> protected abstract void initalize();
>>>
>>> /**
>>> * Mit dieser Methode wird geprüft, ob der Benutzer
>>> * das Icon überhaupt sehen/ankilcken darf
>>> * */
>>> public abstract boolean hasPermission(int user_type);
>>>
>>> /**
>>> * Mit dieser Methode wird das Icon gezeichnet
>>> * */
>>> public void draw(Display d, DBCon dbcon, int user_type){
>>> System.out.print(Thread.currentThread().toString());
>>> System.out.print(", ");
>>> System.out.println(d.getThread().toString());
>>> if(hasPermission(user_type)){
>>> s = new Shell(d, SWT.NO_TRIM);
>>> s.setBackground(d.getSystemColor(SWT.COLOR_WHITE));
>>> this.dbcon = dbcon;
>>> this.d = d;
>>> s.setData(WidgetUtil.CUSTOM_VARIANT, "Icon");
>>> s.setLayout(new FillLayout());
>>>
>>> Button b = new Button(s, SWT.FLAT);
>>> b.setBackground(d.getSystemColor(SWT.COLOR_WHITE));
>>> b.setImage(icon);
>>> b.setToolTipText(tooltip);
>>> b.addSelectionListener(this);
>>> b.addMouseListener(this);
>>> b.setData(WidgetUtil.CUSTOM_VARIANT, "Icon");
>>>
>>> s.setSize(width, height);
>>> Point p = dbcon.getPos(id);
>>> if(p != null)
>>> s.setLocation(p.x, p.y);
>>> else
>>> s.setLocation(x, y);
>>> s.setVisible(true);
>>> }
>>> }
>>>
>>> public void mouseDoubleClick(MouseEvent e) {
>>> }
>>>
>>> public void mouseDown(MouseEvent e) {
>>> }
>>>
>>> public void widgetDefaultSelected(SelectionEvent e) {
>>> }
>>>
>>> public void mouseUp(MouseEvent e) {
>>> if(e.button == 2){
>>> s.setLocation(e.x, e.y);
>>> if(!dbcon.setPos(new Point(e.x, e.y), id))
>>> MessageDialog.showError(d, "Konnte die Position des
>>> Icons nicht speichern!");
>>> }
>>> }
>>> }
>>>
>>> LogoutIcon.java:
>>>
>>> package mpw_main.ui;
>>>
>>> import java.util.logging.Level;
>>> import java.util.logging.Logger;
>>>
>>> import org.eclipse.rwt.RWT;
>>> import org.eclipse.rwt.graphics.Graphics;
>>> import org.eclipse.swt.events.SelectionEvent;
>>>
>>> public class LogoutIcon extends Icon {
>>>
>>> public boolean hasPermission(int user_type) {
>>> return true;
>>> }
>>>
>>> protected void initalize() {
>>> icon = Graphics.getImage("images/icon-logout.png",
>>> getClass().getClassLoader());
>>> x = 128;
>>> y = 300;
>>> width = 70;
>>> height = 70;
>>> tooltip = "Logout";
>>> id = 1;
>>> }
>>>
>>> public void widgetSelected(SelectionEvent f) {
>>> System.out.print(Thread.currentThread().toString());
>>> System.out.print(", ");
>>> System.out.println(d.getThread().toString());
>>> dbcon.logout();
>>> try{
>>> RWT.getResponse().sendRedirect("http://www.google.de");
>>> } catch(Exception e){
>>> Logger.getLogger("mpw").log(Level.SEVERE, "Couldn't kick
>>> the user", e);
>>> }
>>> //TODO: Kick the user
>>> }
>>>
>>> }
>>>
>>>
>>> AboutIcon.java:
>>>
>>> public class AboutIcon extends Icon {
>>>
>>> public boolean hasPermission(int user_type) {
>>> return true;
>>> }
>>>
>>> protected void initalize() {
>>> icon = Graphics.getImage("images/icon-about.png",
>>> getClass().getClassLoader());
>>> x = 0;
>>> y = 300;
>>> width = 70;
>>> height = 70;
>>> tooltip = "Über";
>>> id = 0;
>>> }
>>>
>>> public void widgetSelected(SelectionEvent e) {
>>> /*d.syncExec(new Runnable(){
>>> public void run(){
>>> new AboutDialog(d);
>>> }
>>> });*/
>>> System.out.print(Thread.currentThread().toString());
>>> System.out.print(", ");
>>> System.out.println(d.getThread().toString());
>>> }
>>> }
Previous Topic:OSGi shutdown problems
Next Topic:SWT.EMBEDDED alternative?
Goto Forum:
  


Current Time: Sun Jan 29 13:50:59 GMT 2023

Powered by FUDForum. Page generated in 0.05804 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top