Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 17

Discussione: errore...eccezioni

  1. #1

    errore...eccezioni

    Questa è un semplice jpanel con una jmenubar.
    Ho una lista di Jcombobox e devo praticamente dopo aver cliccato "avvia" far partire uno dopo l'altro una serie di eseguibili.

    A runtime ho diversi errori nati da quando ho iniziato a lavorare con gli eseguibili, il resto va tutto bene, credo sia una questione di gestione dell'eccezioni.....mi date una mano?

    questo è il codice:
    codice:
    import java.io.*;
    import java.net.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class NeuroStim extends JPanel implements ActionListener{
    	JButton avvia_test = null;
    	JMenuItem infoTest;
    	JMenuItem exitItem;
    	JMenuItem aboutItem;
    	JLabel nome_paziente;
    	JTextField nomePaziente;
    	JLabel test1;
    	JLabel test2;
    	JLabel test3;
    	JLabel test4;
    	JLabel test5;
    	JLabel test6;
    	JLabel test7;
    	JLabel test8;
    	JLabel test9;
    	JLabel test10;
    	JLabel test11;
    	JLabel test12;
    	JComboBox test01;
    	JComboBox test02;
    	JComboBox test03;
    	JComboBox test04;
    	JComboBox test05;
    	JComboBox test06;
    	JComboBox test07;
    	JComboBox test08;
    	JComboBox test09;
    	JComboBox test010;
    	JComboBox test011;
    	JComboBox test012;
    	String[] Lista_test; 
    	ImageIcon a;
    	
    	
    	public NeuroStim(Container pane)
    	{
    		 pane.setLayout(new GridLayout(30,3));	
    	
    	JMenuBar menubar = new JMenuBar();
    
    	JMenu menuStart, help;
    	menuStart = new JMenu("     File               ");
    	menuStart.setMnemonic(KeyEvent.VK_H);
    	menubar.add(menuStart);
    	
    	exitItem = new JMenuItem("Chiudi", KeyEvent.VK_X);
    	exitItem.addActionListener(this);
    	menuStart.add(exitItem);
    
    	help = new JMenu("   Help                 ");
    	help.setMnemonic(KeyEvent.VK_H);
    	menubar.add(help);
    
    
    	infoTest = new JMenuItem("Info test", KeyEvent.VK_H);
    	infoTest.addActionListener(this);
    	help.add(infoTest);
    
    	aboutItem = new JMenuItem("Info");
    	help.add(aboutItem);
    	aboutItem.addActionListener(this);
    	
    	Lista_test = new String[13]; 
    	Lista_test[0]="BloccoAfacile";
         Lista_test[1]="Blocco B facile";
         Lista_test[2]="Blocco C facile";
         Lista_test[3]="Blocco D facile";
         Lista_test[4]="Blocco E facile";
         Lista_test[5]="Blocco F facile";
         Lista_test[6]="Blocco A medio";
         Lista_test[7]="Blocco B medio";
         Lista_test[8]="Blocco C medio";
         Lista_test[9]="Blocco D medio";
         Lista_test[10]="Blocco E medio";
         Lista_test[11]="Blocco F medio";
         Lista_test[12]="Blocco Fissazione";
         
    	test01= new JComboBox(Lista_test); 
        test01.addActionListener(this);
        test02= new JComboBox(Lista_test); 
        test02.addActionListener(this);
        test03= new JComboBox(Lista_test); 
        test03.addActionListener(this);
        test04= new JComboBox(Lista_test); 
        test04.addActionListener(this);
        test05= new JComboBox(Lista_test); 
        test05.addActionListener(this);
        test06= new JComboBox(Lista_test); 
        test06.addActionListener(this);
        test07= new JComboBox(Lista_test); 
        test07.addActionListener(this);
        test08= new JComboBox(Lista_test); 
        test08.addActionListener(this);
        test09= new JComboBox(Lista_test); 
        test09.addActionListener(this);
        test010= new JComboBox(Lista_test); 
        test010.addActionListener(this);
        test011= new JComboBox(Lista_test); 
        test011.addActionListener(this);
        test012= new JComboBox(Lista_test); 
        test012.addActionListener(this);
        
        nome_paziente = new JLabel("nome paziente: ");
        
        test1=new JLabel ("blocco1:");
        test2=new JLabel ("blocco2:");
        test3=new JLabel ("blocco3:");
        test4=new JLabel ("blocco4:");
        test5=new JLabel ("blocco5:");
        test6=new JLabel ("blocco6:");
        test7=new JLabel ("blocco7:");
        test8=new JLabel ("blocco8:");
        test9=new JLabel ("blocco9:");
        test10=new JLabel ("blocco10:");
        test11=new JLabel ("blocco11:");
        test12=new JLabel ("blocco12:");
        
        nomePaziente= new JTextField();
    
    	pane.add(menubar, BorderLayout.NORTH);
    	pane.add(nome_paziente);
        pane.add(nomePaziente);
    	pane.add(test1);    
    	pane.add(test01);
        pane.add(test2);
        pane.add(test02);
        pane.add(test3);
        pane.add(test03);
        pane.add(test4);
        pane.add(test04);
        pane.add(test5);
        pane.add(test05);
        pane.add(test6);
        pane.add(test06);
        pane.add(test7);
        pane.add(test07);
        pane.add(test8);
        pane.add(test08);
        pane.add(test9);
        pane.add(test09);
        pane.add(test10);
        pane.add(test010);
        pane.add(test11);
        pane.add(test011);
        pane.add(test12);
        pane.add(test012);
        
        ImageIcon mioLogo = new ImageIcon("C:/prova.gif");
    	JLabel miaLabel = new JLabel( mioLogo );
    
    	pane.add(miaLabel);
    	pane.validate();
    	
        
        avvia_test(pane);
        
    	}
    	
    	private void avvia_test(Container container)
    	{
    	avvia_test = new JButton("    Avvia test     ");
    	container.add(avvia_test);
    	avvia_test.addActionListener(this);
    	}
    	
    	public void actionPerformed(ActionEvent e)
    	{
    	Object source = e.getSource();
    	if(source==avvia_test)
    	{
    		if (nomePaziente.getText().length() == 0){
    		JOptionPane.showMessageDialog(null,
    				"Tutti i campi devono essere riempiti",
    				"Messaggio di errore",
    				JOptionPane.WARNING_MESSAGE);}
    		else {                                                      //il problema nasce da qui
    				{
    					String[] eseguibile= new String[13];
    					for (int i=0; i<13; i++){
    						if(test01.getSelectedItem()=="bloccoAfacile")
    							eseguibile[i]="c:/bloccoAfacile.exe";
    					}
    					for (int i=0; i<13; i++){
    						try {
    							Runtime.getRuntime().exec(eseguibile[i]);
    						} catch (IOException e1) {
    							// TODO Auto-generated catch block
    							e1.printStackTrace();
    						}
    						try {
    							Runtime.getRuntime().exec("c:/bloccoFissazione.exe");
    						} catch (IOException e1) {
    							// TODO Auto-generated catch block
    							e1.printStackTrace();
    						}
    						
    					}
    				}
    				
    		
    	
    	}
    	}
    
    	if (source == exitItem){
    		int ris;
    	ris=JOptionPane.showConfirmDialog(null,
    	"Sei sicuro di voler uscire?","Conferma uscita",
    	JOptionPane.YES_NO_OPTION);
    	if(ris==JOptionPane.YES_OPTION)
    	System.exit(1);
    	}
    
    	else if (source == aboutItem) {
    	    JOptionPane.showMessageDialog(
    	        NeuroStim.this,
    	        "Test neuropsicologici ",
    	        "tesi di laurea",
    	        JOptionPane.PLAIN_MESSAGE);
    	}
    	else if (source == infoTest) {
    		
    	    JOptionPane.showMessageDialog(
    	        NeuroStim.this,
    	        "test numero 1\n" +
    	        "test numero 2\n" +
    	        "test numero 3\n" +
    	        "test numero 4\n" +
    	        "test numero 5\n" +
    	        "test numero 6\n" ,
    	        "test disponibili",
    	        JOptionPane.PLAIN_MESSAGE);
    	}
    		
    	}
    	private static void createAndShowGUI()
    	{
    
    	JFrame frame = new JFrame("NeuroStim");
    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	NeuroStim msm = new NeuroStim(frame.getContentPane());
    	frame.pack();
    	frame.setVisible(true);
    	}
    
    	public static void main(String[] args) {
    
    		javax.swing.SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    			createAndShowGUI();
    			}
    			});
    			}
    
    	}

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    ehm che eccezioni sono?
    posta il trace o descrivi il comportamento anomalo (e un hint su come lo ottieni)

  3. #3
    run

    inserisco nome paziente (altrimenti non mi fa proseguire)
    quindi salto l'if e entro nell'else
    il primo checkbox è bloccoAfacile quindi dovrebbe partire l'esecuzione di due eseguibili e invece:


    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at java.lang.Runtime.exec(Runtime.java:424)
    at java.lang.Runtime.exec(Runtime.java:328)
    at neurostim.NeuroStim.actionPerformed(NeuroStim.java :202)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6263)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:602 8)
    at java.awt.Container.processEvent(Container.java:204 1)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4630)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4574)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478 )
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)

  4. #4
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    java.lang.NullPointerException

    indica qualcosa di non inizializzato che se ho capito bene è un qualcosa legato all'eseguibile(infatti è dentro runtime)

    poi orrore cosa è?

    codice:
    for (int i=0; i<13; i++){
    	if(test01.getSelectedItem()=="bloccoAfacile")
    		eseguibile[i]="c:/bloccoAfacile.exe";
    }
    due stringhe si confrontano con equals, non con == (in generale usato solo per i tipi primitivi o se devi controllare che due oggetti abbiamo lo stesso riferimento).

  5. #5
    ooooooooooooooooooops....


    if(test01.getSelectedItem().equals("bloccoAfacile" ))




    all'interno dell'eseguibile? e cosa potrebbe essere?

  6. #6
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    non so, io vedo

    codice:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at java.lang.Runtime.exec(Runtime.java:424)
    è all'interno della exec che si verifica questo problema, desumo che quello che gli passi sia null

  7. #7
    no l'eseguibile funziona....

    il problema è far eseguire, una carrellata di eseguibili!

    Se tolgo il secondo try catch funziona, ma a me serve mandare una serie di eseguibili.......come posso fare? :S

  8. #8
    forse ho risolto...esiste un metodo per far si che il secondo eseguibile parti quando il primo è terminato?

  9. #9
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    eh allora prova a debuggare e a vedere cosa succede passo per passo, NullPointerException è qualcosa di non inizializzato, dal trace desumo che si presenti li perché è il primo punto che ti dà, di più non so dirti

  10. #10
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    allora chiamare una roba runtime significa avviare un altro processo che non è detto finisca prima del nuovo che tu vuoi andare ad eseguire, qui esuli un po dalla programmazione java pura perché sposti l'attenzione su quello che succede a livello di sistema operativo.

    Puoi temporizzare in qualche modo, cercare il valore di ritorno....ma se ne devi fare uno dopo l'altro forse questo approccio non è il migliore (almeno per le mie conoscenze)

    Ma tu di questi exe non hai i sorgenti?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.