Ecco il codice completo del file MyDBConn.java (ditemi se serve anche il file che richiama la funzione):
E questo è l'output:codice:package cc; import java.sql.*; public class MyDBConn { private Connection myConnection; private java.sql.Statement stmt; /** Creates a new instance of MyDBConn */ public MyDBConn() { } public void init(){ try{ Class.forName("Driver"); myConnection=DriverManager.getConnection( "URL", "user", "pass" ); } catch(Exception es){ alerts.showErr(es.getMessage()); } } public ResultSet getResultFromPazienti2(String query) { ResultSet rs=null; try{ rs=stmt.executeQuery(query); } catch(Exception e){ e.printStackTrace(); } return rs; } ///////////// RESULT public Connection getMyConnection(){ return myConnection; } public void close(ResultSet rs){ if(rs !=null){ try{ rs.close(); } catch(Exception e){} } } public void close(java.sql.Statement stmt){ if(stmt !=null){ try{ stmt.close(); } catch(SQLException e){} System.out.println("ERRORE"); } } public void destroy(){ if(myConnection !=null){ try{ myConnection.close(); } catch(Exception e){} } } }
codice:java.lang.NullPointerException at cc.MyDBConn.getResultFromPazienti2(MyDBConn.java:51) (corrisponde alla riga rossa del file sopra) at cc.Paziente.formWindowOpened(Paziente.java:522) at cc.Paziente.access$000(Paziente.java:14) at cc.Paziente$2.windowOpened(Paziente.java:108) at java.awt.Window.processWindowEvent(Window.java:1187) at javax.swing.JFrame.processWindowEvent(JFrame.java:266) at java.awt.Window.processEvent(Window.java:1148) at java.awt.Component.dispatchEventImpl(Component.java:3955) at java.awt.Container.dispatchEventImpl(Container.java:2024) at java.awt.Window.dispatchEventImpl(Window.java:1778) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.EventQueue.dispatchEvent(EventQueue.java:463) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149) at java.awt.EventDispatchThread.run(EventDispatchThread.java:110) Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at cc.Paziente.formWindowOpened(Paziente.java:525) at cc.Paziente.access$000(Paziente.java:14) at cc.Paziente$2.windowOpened(Paziente.java:108) at java.awt.Window.processWindowEvent(Window.java:1187) at javax.swing.JFrame.processWindowEvent(JFrame.java:266) at java.awt.Window.processEvent(Window.java:1148) at java.awt.Component.dispatchEventImpl(Component.java:3955) at java.awt.Container.dispatchEventImpl(Container.java:2024) at java.awt.Window.dispatchEventImpl(Window.java:1778) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.EventQueue.dispatchEvent(EventQueue.java:463) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149) at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Rispondi quotando