IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Eclipse Platform Discussion :

invocationTargetException et ouverture de Shell


Sujet :

Eclipse Platform

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Août 2007
    Messages
    173
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 173
    Par défaut invocationTargetException et ouverture de Shell
    Bonjour la liste,

    J'éxécute une mini application RCP. J'utilise un objet Wizard (org.eclipse.jface.wizard.Wizard).
    Le code de ma classe Wizard est le suivant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    public class ReservationWizard extends Wizard {
    	  
    	...
              public void addPages() {
    	    addPage(new FrontPage());
    	    addPage(new CustomerInfoPage());
    	    addPage(new PaymentInfoPage());
    	  }    
    
    	  public boolean performFinish() {
    	    ...
    	    try {
    	      // puts the data into a database ...
    	      getContainer().run(true, true, new IRunnableWithProgress() {
    	        public void run(IProgressMonitor monitor)
    	          throws InvocationTargetException, InterruptedException {
    	          monitor.beginTask("Store data", 100);
    	          monitor.worked(40);
    	          
    	          // store data here ...
    	          System.out.println(data);
    	          
    	          WidgetTest test = new WidgetTest();
    		  Shell shell = test.getShell();
    		  shell.open();
    		          
    	          
    	          Thread.sleep(2000);
    	          monitor.done();
    	        }
    	      });
    	    } catch (InvocationTargetException e) {
    	      e.printStackTrace();
    	    } catch (InterruptedException e) {
    	      e.printStackTrace();
    	    }catch (Exception e) {
    	      e.printStackTrace();
    	    }
    	    //Display.getCurrent().dispose();
    	    return true;
    	  }
    
    	  /* (non-Javadoc)
    	   * @see org.eclipse.jface.wizard.IWizard#performCancel()
    	   */
    	  public boolean performCancel() {
    	   ...
    	  }  
    	}
    Une fois cliqué sur le bouton Finish, j'ouvre un shell. Le code de ce shell est le suivant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    public class WidgetTest {
     
    	Shell topLevelShell = null;
     
    	public WidgetTest(){
    		topLevelShell = new Shell();
    		topLevelShell.setText("TopLevel.LigneTitre");
    		topLevelShell.setLayout(new GridLayout());
    		Button btnOpen = new Button(topLevelShell,SWT.PUSH);
    		btnOpen.setText("Ouvrir");
    		btnOpen.addSelectionListener(new SelectionListener(){
     
    			@Override
    			public void widgetDefaultSelected(SelectionEvent e) {
    				// TODO Auto-generated method stub
     
    			}
     
    			@Override
    			public void widgetSelected(SelectionEvent e) {
    				// TODO Auto-generated method stub
    				System.out.println("Bienvenue à Libreville");
    			}
     
    		});
     
    	}
    	public Shell getShell(){
    		return topLevelShell;
    	}
     
    }
    Mais seulement lors de l'exécution, quand je clique sur "Finish", j'ai l'erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    java.lang.reflect.InvocationTargetException
    	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:415)
    	at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:934)
    	at wizardtest.handler.ReservationWizard.performFinish(ReservationWizard.java:75)
    	at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:742)
    	at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:373)
    	at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
    	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
    	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1158)
    	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3401)
    	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3033)
    	at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
    	at org.eclipse.jface.window.Window.open(Window.java:801)
    	at wizardtest.handler.WizardHandler.execute(WizardHandler.java:19)
    	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:281)
    	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
    	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
    	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
    	at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:247)
    	at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:619)
    	at org.eclipse.ui.menus.CommandContributionItem.access$10(CommandContributionItem.java:605)
    	at org.eclipse.ui.menus.CommandContributionItem$4.handleEvent(CommandContributionItem.java:595)
    	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1158)
    	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3401)
    	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3033)
    	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
    	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
    	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
    	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(Workbench.java:488)
    	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    	at wizardtest.Application.start(Application.java:20)
    	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.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(EclipseStarter.java:386)
    	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	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: org.eclipse.swt.SWTException: Invalid thread access
    	at org.eclipse.swt.SWT.error(SWT.java:3777)
    	at org.eclipse.swt.SWT.error(SWT.java:3695)
    	at org.eclipse.swt.SWT.error(SWT.java:3666)
    	at org.eclipse.swt.widgets.Widget.error(Widget.java:446)
    	at org.eclipse.swt.widgets.Shell.<init>(Shell.java:254)
    	at org.eclipse.swt.widgets.Shell.<init>(Shell.java:245)
    	at org.eclipse.swt.widgets.Shell.<init>(Shell.java:199)
    	at org.eclipse.swt.widgets.Shell.<init>(Shell.java:138)
    	at wizardtest.handler.WidgetTest.<init>(WidgetTest.java:19)
    	at wizardtest.handler.ReservationWizard$1.run(ReservationWizard.java:84)
    	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
    Si quelqu'un a une explication ou bien les pistes pour remédier à la situation, merci beaucoup d'avance.

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Août 2007
    Messages
    173
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 173
    Par défaut
    Citation Envoyé par caro_caro Voir le message
    Bonjour la liste,

    J'éxécute une mini application RCP. J'utilise un objet Wizard (org.eclipse.jface.wizard.Wizard).
    Le code de ma classe Wizard est le suivant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    public class ReservationWizard extends Wizard {
    	  
    	...
              public void addPages() {
    	    addPage(new FrontPage());
    	    addPage(new CustomerInfoPage());
    	    addPage(new PaymentInfoPage());
    	  }    
    
    	  public boolean performFinish() {
    	    ...
    	    try {
    	      // puts the data into a database ...
    	      getContainer().run(true, true, new IRunnableWithProgress() {
    	        public void run(IProgressMonitor monitor)
    	          throws InvocationTargetException, InterruptedException {
    	          monitor.beginTask("Store data", 100);
    	          monitor.worked(40);
    	          
    	          // store data here ...
    	          System.out.println(data);
    	          
    	          WidgetTest test = new WidgetTest();
    		  Shell shell = test.getShell();
    		  shell.open();
    		          
    	          
    	          Thread.sleep(2000);
    	          monitor.done();
    	        }
    	      });
    	    } catch (InvocationTargetException e) {
    	      e.printStackTrace();
    	    } catch (InterruptedException e) {
    	      e.printStackTrace();
    	    }catch (Exception e) {
    	      e.printStackTrace();
    	    }
    	    //Display.getCurrent().dispose();
    	    return true;
    	  }
    
    	  /* (non-Javadoc)
    	   * @see org.eclipse.jface.wizard.IWizard#performCancel()
    	   */
    	  public boolean performCancel() {
    	   ...
    	  }  
    	}
    Une fois cliqué sur le bouton Finish, j'ouvre un shell. Le code de ce shell est le suivant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    public class WidgetTest {
     
    	Shell topLevelShell = null;
     
    	public WidgetTest(){
    		topLevelShell = new Shell();
    		topLevelShell.setText("TopLevel.LigneTitre");
    		topLevelShell.setLayout(new GridLayout());
    		Button btnOpen = new Button(topLevelShell,SWT.PUSH);
    		btnOpen.setText("Ouvrir");
    		btnOpen.addSelectionListener(new SelectionListener(){
     
    			@Override
    			public void widgetDefaultSelected(SelectionEvent e) {
    				// TODO Auto-generated method stub
     
    			}
     
    			@Override
    			public void widgetSelected(SelectionEvent e) {
    				// TODO Auto-generated method stub
    				System.out.println("Bienvenue à Libreville");
    			}
     
    		});
     
    	}
    	public Shell getShell(){
    		return topLevelShell;
    	}
     
    }
    Mais seulement lors de l'exécution, quand je clique sur "Finish", j'ai l'erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    java.lang.reflect.InvocationTargetException
    	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:415)
    	at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:934)
    	at wizardtest.handler.ReservationWizard.performFinish(ReservationWizard.java:75)
    	at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:742)
    	at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:373)
    	at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
    	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
    	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1158)
    	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3401)
    	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3033)
    	at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
    	at org.eclipse.jface.window.Window.open(Window.java:801)
    	at wizardtest.handler.WizardHandler.execute(WizardHandler.java:19)
    	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:281)
    	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
    	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
    	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
    	at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:247)
    	at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:619)
    	at org.eclipse.ui.menus.CommandContributionItem.access$10(CommandContributionItem.java:605)
    	at org.eclipse.ui.menus.CommandContributionItem$4.handleEvent(CommandContributionItem.java:595)
    	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1158)
    	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3401)
    	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3033)
    	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
    	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
    	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
    	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(Workbench.java:488)
    	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    	at wizardtest.Application.start(Application.java:20)
    	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.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(EclipseStarter.java:386)
    	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	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: org.eclipse.swt.SWTException: Invalid thread access
    	at org.eclipse.swt.SWT.error(SWT.java:3777)
    	at org.eclipse.swt.SWT.error(SWT.java:3695)
    	at org.eclipse.swt.SWT.error(SWT.java:3666)
    	at org.eclipse.swt.widgets.Widget.error(Widget.java:446)
    	at org.eclipse.swt.widgets.Shell.<init>(Shell.java:254)
    	at org.eclipse.swt.widgets.Shell.<init>(Shell.java:245)
    	at org.eclipse.swt.widgets.Shell.<init>(Shell.java:199)
    	at org.eclipse.swt.widgets.Shell.<init>(Shell.java:138)
    	at wizardtest.handler.WidgetTest.<init>(WidgetTest.java:19)
    	at wizardtest.handler.ReservationWizard$1.run(ReservationWizard.java:84)
    	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
    Si quelqu'un a une explication ou bien les pistes pour remédier à la situation, merci beaucoup d'avance.
    J'ai rémedié à la situation.. En fait, il suffisait d'écrire le code qui ouvre la nouvelle fenêtre ainsi
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     Display.getDefault().asyncExec(new Runnable(){
    		          public void run(){
    		          WidgetTest test = new WidgetTest();
    			 	  Shell shell = test.getShell();
    			 	  shell.open();
    		          }
    	          });
    Cela résoud le problème qui était
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SWTException Invalid Thread Access
    Actuellement, j'ai un nouveau problème
    Lorsque le shell "fen" s'ouvre, immédiatement après c'est le shell principal qui redevient actif.
    Comment faire si bien que c'est fen1 qui reste active?

    Merci beaucoup d'avance

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. PHP/SHELL/apache ouverture console probleme
    Par hash dans le forum Linux
    Réponses: 2
    Dernier message: 27/01/2010, 16h31
  2. Réponses: 1
    Dernier message: 15/10/2009, 17h32
  3. Ouverture "glissée" d'un shell
    Par pathfinder06 dans le forum SWT/JFace
    Réponses: 5
    Dernier message: 25/03/2009, 09h40
  4. Réponses: 3
    Dernier message: 06/05/2008, 20h43
  5. Shell automatique à l'ouverture de session
    Par fredouzzz dans le forum Ubuntu
    Réponses: 14
    Dernier message: 27/02/2008, 12h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo