Can't update TableViewer when Button is pressed [message #329488] |
Thu, 26 June 2008 00:51  |
Eclipse User |
|
|
|
Originally posted by: hardy.oei.gmail.com
dear all,
I have a Button class that add a AddUserListener class so that whenever
a user clicked on it, it will reload the database data into the
TableViewer model and refresh the TableViewer. But then, I'm unable to
do so. Something is wrong and I don't know why.
This is a snippet of my code:
public class AddUserListener implements SelectionListener{
..
..
public void widgetSelected(SelectionEvent e) {
if(passwordForm.getText().equals(confirmPasswordForm.getText ())){
DBConnection.openConnection();
DBConnection.update("Insert into USER Values('"
+ userNameForm.getText()+"','"
+ nameForm.getText()+"','"
+ passwordForm.getText()+"','"
+ emailForm.getText()+"','"
+ new Date(Calendar.getInstance().getTime().getTime())
+ "')");
DBConnection.closeConnection();
//When this is called the table
//should update itself using
//refresh();
userTableViewer.notifyViewer();
//the application never execute these lines below
String message = "User with "
+ userNameForm.getText()
+" Success"; MessageDialog.openInformation(
((Button)e.getSource()).getShell()
, "Add User Success", message);
userNameForm.setText("");
nameForm.setText("");
passwordForm.setText("");
confirmPasswordForm.setText("");
emailForm.setText("");
}
}
..
..
}
This is the content of userTableViewer.notifyViewer() in the
UserTableViewer class :
public void notifyViewer() {
Display display = PlatformUI.getWorkbench().getDisplay();
display.asyncExec(new Runnable(){
public void run(){
DBConnection.openConnection();
ResultSet rs;
final CachedRowSet crs;
try {
rs = DBConnection.query("SELECT * FROM USER");
crs = new CachedRowSetImpl();
crs.populate(rs);
userTableViewer.refresh(crs);
DBConnection.closeConnection();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
});
}
I try to debug my program using eclipse, butwhenever the debug cursor
reach userTableViewer.notifyViewer(); line, it always goes to the
EventTable class. It seems that the application never execute the
userTableViewer.notifyViewer() line.
public void sendEvent (Event event) {
if (types == null) return;
level += level >= 0 ? 1 : -1;
try {
for (int i=0; i<types.length; i++) {
if (event.type == SWT.None) return;
if (types [i] == event.type) {
Listener listener = listeners [i];
if (listener != null) listener.handleEvent (event);
}
}
//The debug cursor start at this line.
} finally {
boolean compact = level < 0;
level -= level >= 0 ? 1 : -1;
if (compact && level == 0) {
int index = 0;
for (int i=0; i<types.length; i++) {
if (types [i] != 0) {
types [index] = types [i];
listeners [index] = listeners [i];
index++;
}
}
for (int i=index; i<types.length; i++) {
types [i] = 0;
listeners [i] = null;
}
}
}
}
That's my problem. I would be very grateful if someone have a look at my
problem and give a solution on it.
Regards,
Hardy
|
|
|
|
|
|
|
|
Re: Can't update TableViewer when Button is pressed [message #329498 is a reply to message #329497] |
Thu, 26 June 2008 04:30   |
Eclipse User |
|
|
|
Originally posted by: hardy.oei.gmail.com
Tom Schindl wrote:
> What's the code at AddUserListener.java:82?
>
> Tom
>
I've rewrite UserTableViewer class so that I can know which code is
really giving me the error.
Here is the class snippet:
if(passwordForm.getText().equals(confirmPasswordForm.getText ())){
DBConnection.openConnection();
DBConnection.update("Insert into USER Values('"
+ userNameForm.getText()+"','"
+ nameForm.getText()+"','"
+ passwordForm.getText()+"','"
+ emailForm.getText()+"','"
+ new Date(Calendar.getInstance().getTime().getTime())
+ "')");
DBConnection.closeConnection();
Display display = PlatformUI.getWorkbench().getDisplay();
DBConnection.openConnection();
ResultSet rs;
final CachedRowSet crs;
try {
rs = DBConnection.query("SELECT * FROM USER");
crs = new CachedRowSetImpl();
crs.populate(rs);
userTableViewer.setInput(crs);
display.asyncExec(new Runnable(){
public void run(){
userTableViewer.setInput(crs);
userTableViewer.refresh(false);
}
});
DBConnection.closeConnection();
}catch (SQLException ex) {
ex.printStackTrace();
}
String message = "User with "+ userNameForm.getText()+" adding success";
MessageDialog.openInformation(
((Button)e.getSource()
).getShell(), "Add User Success", message); userNameForm.setText("");
nameForm.setText("");
passwordForm.setText("");
confirmPasswordForm.setText("");
emailForm.setText("");
}
}
It give me this error
(com.blodstone.server.rcp.views.listeners.AddUserListener.wi dgetSelected(AddUserListener.java:94)is
MessageDialog.openInformation(((Button)e.getSource()).getShe ll(),
"Add User Success", message); )
:
!SESSION 2008-06-26 16:16:23.078
-----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_01
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=in_ID
Framework arguments: -product com.blodstone.server.rcp.product
Command-line arguments: -product com.blodstone.server.rcp.product -data
C:\Documents and
Settings\Supervisor\workspace/../runtime-com.blodstone.serve r.rcp.application
-dev file:C:/Documents and
Settings/Supervisor/workspace/.metadata/.plugins/org.eclipse .pde.core/com.blodstone.server.rcp.application/dev.propertie s
-os win32 -ws win32 -arch x86 -consoleLog
!ENTRY org.eclipse.ui 4 0 2008-06-26 16:16:34.437
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.swt.SWTException: Failed to execute runnable
(java.lang.NullPointerException)
at org.eclipse.swt.SWT.error(SWT.java:3777)
at org.eclipse.swt.SWT.error(SWT.java:3695)
at
org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:136)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:3800)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3425)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825 )
at org.eclipse.jface.window.Window.open(Window.java:801)
at
org.eclipse.jface.dialogs.MessageDialog.openInformation(Mess ageDialog.java:346)
at
com.blodstone.server.rcp.views.listeners.AddUserListener.wid getSelected(AddUserListener.java:94)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:228)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3422)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2382)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:21 98)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:288)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:488)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at com.blodstone.server.rcp.Application.start(Application.java: 20)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:193)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:382)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Caused by: java.lang.NullPointerException
at
com.blodstone.server.rcp.views.listeners.AddUserListener$1.r un(AddUserListener.java:85)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
at
org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:133)
... 32 more
Regards,
Hardy
|
|
|
Re: Can't update TableViewer when Button is pressed [message #329500 is a reply to message #329498] |
Thu, 26 June 2008 05:09   |
Eclipse User |
|
|
|
My guess is that:
e.getSource() is null. You should use e.widget instead.
Tom
Hardy schrieb:
> Tom Schindl wrote:
>> What's the code at AddUserListener.java:82?
>>
>> Tom
>>
> I've rewrite UserTableViewer class so that I can know which code is
> really giving me the error.
>
> Here is the class snippet:
>
> if(passwordForm.getText().equals(confirmPasswordForm.getText ())){
> DBConnection.openConnection();
> DBConnection.update("Insert into USER Values('"
> + userNameForm.getText()+"','"
> + nameForm.getText()+"','"
> + passwordForm.getText()+"','"
> + emailForm.getText()+"','"
> + new Date(Calendar.getInstance().getTime().getTime())
> + "')");
> DBConnection.closeConnection();
> Display display = PlatformUI.getWorkbench().getDisplay();
> DBConnection.openConnection();
> ResultSet rs;
> final CachedRowSet crs;
> try {
> rs = DBConnection.query("SELECT * FROM USER");
> crs = new CachedRowSetImpl();
> crs.populate(rs);
> userTableViewer.setInput(crs);
> display.asyncExec(new Runnable(){
> public void run(){
> userTableViewer.setInput(crs);
> userTableViewer.refresh(false);
> }
> });
> DBConnection.closeConnection();
> }catch (SQLException ex) {
> ex.printStackTrace();
> }
> String message = "User with "+ userNameForm.getText()+" adding
> success";
> MessageDialog.openInformation(
> ((Button)e.getSource()
> ).getShell(), "Add User Success", message);
> userNameForm.setText("");
> nameForm.setText("");
> passwordForm.setText("");
> confirmPasswordForm.setText("");
> emailForm.setText("");
> }
> }
>
> It give me this error
> (com.blodstone.server.rcp.views.listeners.AddUserListener.wi dgetSelected(AddUserListener.java:94)is
>
> MessageDialog.openInformation(((Button)e.getSource()).getShe ll(), "Add
> User Success", message); )
>
> :
>
> !SESSION 2008-06-26 16:16:23.078
> -----------------------------------------------
> eclipse.buildId=unknown
> java.version=1.6.0_01
> java.vendor=Sun Microsystems Inc.
> BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=in_ID
> Framework arguments: -product com.blodstone.server.rcp.product
> Command-line arguments: -product com.blodstone.server.rcp.product -data
> C:\Documents and
> Settings\Supervisor\workspace/../runtime-com.blodstone.serve r.rcp.application
> -dev file:C:/Documents and
> Settings/Supervisor/workspace/.metadata/.plugins/org.eclipse .pde.core/com.blodstone.server.rcp.application/dev.propertie s
> -os win32 -ws win32 -arch x86 -consoleLog
>
> !ENTRY org.eclipse.ui 4 0 2008-06-26 16:16:34.437
> !MESSAGE Unhandled event loop exception
> !STACK 0
> org.eclipse.swt.SWTException: Failed to execute runnable
> (java.lang.NullPointerException)
> at org.eclipse.swt.SWT.error(SWT.java:3777)
> at org.eclipse.swt.SWT.error(SWT.java:3695)
> at
> org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:136)
>
> at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:3800)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3425)
> at org.eclipse.jface.window.Window.runEventLoop(Window.java:825 )
> at org.eclipse.jface.window.Window.open(Window.java:801)
> at
> org.eclipse.jface.dialogs.MessageDialog.openInformation(Mess ageDialog.java:346)
>
> at
> com.blodstone.server.rcp.views.listeners.AddUserListener.wid getSelected(AddUserListener.java:94)
>
> at
> org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:228)
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
> at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3823)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3422)
> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2382)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
> at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:21 98)
> at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:288)
>
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:488)
> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
> at com.blodstone.server.rcp.Application.start(Application.java: 20)
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:193)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:382)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 549)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
> Caused by: java.lang.NullPointerException
> at
> com.blodstone.server.rcp.views.listeners.AddUserListener$1.r un(AddUserListener.java:85)
>
> at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
> at
> org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:133)
>
> ... 32 more
>
>
> Regards,
> Hardy
--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
|
|
|
|
|
|
Re: Can't update TableViewer when Button is pressed [message #329506 is a reply to message #329505] |
Thu, 26 June 2008 07:00  |
Eclipse User |
|
|
|
This is the standard event loop and totally correct your problem is that
you are having a NPE somewhere in your code. So do NOT step through your
code with the debugger! Set a Debugger-Rule for NPE and run your program
in debug mode, once more there are NO breakpoints in your code!
To setup such a Exception-Rule simply click on the NPE in your console
you eclipse will lead you through.
Your stacktrace from before tells us that the NPE is so extract
everything into local vars and check what which one is NULL.
Tom
Hardy schrieb:
> Tom Schindl wrote:
>> Hardy please use a Debugger and step through the code and see which
>> variable is null in your case. You could also add a
>> NullPointerException rule this way you can run your code with any
>> break points and can jump right to the line the NPE occurred and
>> inspect the variables.
>>
>> Could it be that "e" is null?
>>
>> Tom
>>
>> Hardy schrieb:
>>> Tom Schindl wrote:
>>>> My guess is that:
>>>>
>>>> e.getSource() is null. You should use e.widget instead.
>>>>
>>>> Tom
>>>>
>>>> Hardy schrieb:
>>>
>>> I changed to
>>> MessageDialog.openInformation(((Button)e.widget).getShell(), "Add
>>> User Success", message);
>>> I still give me the same error log. And the table still won't refresh
>>> itself also.
>>>
>>> regards,
>>> Hardy
>>
>>
>
> I think the problem lies within setinput(crs); because whenever I reach
> that line using my debug. When I reach that line, it always goes to the
> infinite loop within the workbench class. It keeps executing these lines:
> private void runEventLoop(Window.IExceptionHandler handler, Display
> display) {
> runEventLoop = true;
> //The runEventLoop is always true
> while (runEventLoop) {
> try {
> //This is always false
> if (!display.readAndDispatch()) {
> getAdvisor().eventLoopIdle(display);
> }
> } catch (Throwable t) {
> handler.handleException(t);
> // In case Display was closed under us
> if (display.isDisposed())
> runEventLoop = false;
> }
> }
> }
>
> Is this behavior normal?
>
> Regards,
> Hardy
--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
|
|
|
Powered by
FUDForum. Page generated in 0.04343 seconds