Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: how to resolve awt-eventqueue-0 java.lang.nullpointerexception

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to resolve awt-eventqueue-0 java.lang.nullpointerexception

    during the execution of the my application java (developed following design pattern as front controller, dao factory, business object, singleton) i have a problem of connection at this line : Statement st = connessione.createStatement(ResultSet.TYPE_SCROLL_ INSENSITIVE, ResultSet.CONCUR_READ_ONLY); I using the rdbms mysql this problem is presented when I do much query on my db. This is my class that handle the connection with my database.

    public class SQLDAOFactory extends DAOFactory implements AgroludosDAO {
     
    private static final String dbPath="jdbc:mysql://localhost/agroludos";
    private static final String dbUser="root";
    private static final String dbPass="root";
     
    private SQLDAOFactory SQLFactory;
    public static Connection connectDB() {
        Connection connessione = null;
     
        // Caricamento del driver
        try {
            System.out.println("Caricamento Database. Attendere...");       
            connessione = DriverManager.getConnection(dbPath, dbUser, dbPass);
            System.out.println("Connessione OK");
        } catch (SQLException e) {
            JPane.setError(JPane.WARNING_CONNECTION_DATABASE);
            JPane.getError();
           }
     
        return connessione;
    }

    and this is a code that realize my query:

    try {
     
            //Crea uno statement per l'interrogazione del database
            Statement st = connessione.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
     
            //Trace
            System.out.println("Database -> Interrogazione SQL: " + query);     
     
            //Crea un ResultSet eseguendo l'interrogazione desiderata
            ResultSet tabellina = st.executeQuery(query);
            //Trace
            System.out.println("query ok"); 
            return new TableModelCustom(tabellina);
     
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
     
    }

    How to resolve this problem? it is urgent!


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,290
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: how to resolve awt-eventqueue-0 java.lang.nullpointerexception

    Thread moved.

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.
    this problem is presented when I do much query on my db
    What problem is presented? If you're getting an error message, please post that entire message.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to resolve awt-eventqueue-0 java.lang.nullpointerexception

    Quote Originally Posted by GregBrannon View Post
    Thread moved.

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    What problem is presented? If you're getting an error message, please post that entire message.
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at agroludos.database.TipoCompetizioneSQL.getDati(Tip oCompetizioneSQL.java:58)
    at agroludos.database.SQLDAOFactory.getDati(SQLDAOFac tory.java:348)
    at agroludos.business.BOController.getBO(BOController .java:329)
    at agroludos.business.BOController.selectedRow(BOCont roller.java:238)
    at agroludos.boundary.EditorManagerCompetizione$4.mou sePressed(EditorManagerCompetizione.java:312)
    at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

    this is code TipoCompetizioneSQL.getDati and the error is at line :
    Statement enunciato = connessione.createStatement(ResultSet.TYPE_SCROLL_ INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    public static ArrayList<String> getDati(int id_row){
     
    		int id = 0;
    		String tipo = "";
    		String query = "select id,tipo from tipi_competizione where id = "+id_row+";";
    		try{
    			connessione = SQLDAOFactory.connectDB();
    			Statement enunciato = connessione.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    			ResultSet risultato = enunciato.executeQuery(query);
     
     
    			while (risultato.next()) {
    				id = risultato.getInt("id");
    				tipo = risultato.getString("tipo");
    			}			
    		} catch (SQLException e) {
    			JPane.setError(JPane.WARNING_CONNECTION_DATABASE);
    			JPane.getError();
    		}
    		// Popolamento dell'ArrayList con i dati estratti dal database
    		ArrayList<String> campi = new ArrayList<String>();
     
    		String id_str = Integer.toString(id);
    		campi.add(id_str);
    		campi.add(tipo);
    		return campi;	
    	}

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,290
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: how to resolve awt-eventqueue-0 java.lang.nullpointerexception

    A Null Pointer Exception, or NPE, indicates that you've attempted to access an object that has not been initialized or was initialized to null. An object in the line pointed to by the error is null and needs to be initialized to something other than null. You can find which is the offending object by code inspection or adding print statements to print each object.

  5. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to resolve awt-eventqueue-0 java.lang.nullpointerexception

    Quote Originally Posted by GregBrannon View Post
    A Null Pointer Exception, or NPE, indicates that you've attempted to access an object that has not been initialized or was initialized to null. An object in the line pointed to by the error is null and needs to be initialized to something other than null. You can find which is the offending object by code inspection or adding print statements to print each object.
    I have understood that the problem is an object that is null, but this problem don't presented it only in TipoCompetizioneSQL but also in other class and all at same line:
    Statement enunciato = connessione.createStatement(ResultSet.TYPE_SCROLL_ INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    Then the problem I think that is the connection that is null, but this is strange because before this error I did others query without problem.

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,290
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: how to resolve awt-eventqueue-0 java.lang.nullpointerexception

    Then the problem I think . . .
    What you suspect can be easily verified. Once verified (or not) work backwards to determine why something changed and correct it so that the change does not occur.

  7. #7
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to resolve awt-eventqueue-0 java.lang.nullpointerexception

    Quote Originally Posted by GregBrannon View Post
    What you suspect can be easily verified. Once verified (or not) work backwards to determine why something changed and correct it so that the change does not occur.
    the problem is connection because in consolle don't have Connessione OK that comes System.out.println("Connessione OK");.
    What can I do to solve this problem? what are the changes that can be made?
    it's urgent because it is a progam that I have to deliver monday!

Similar Threads

  1. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    By jimbo62 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 19th, 2013, 07:33 AM
  2. Replies: 6
    Last Post: March 21st, 2013, 07:43 AM
  3. Replies: 2
    Last Post: November 24th, 2012, 09:18 AM
  4. Replies: 7
    Last Post: August 13th, 2011, 02:22 AM
  5. Getting "AWT-EventQueue-0" java.lang.NullPointerException error
    By tryingtoJava in forum AWT / Java Swing
    Replies: 9
    Last Post: September 21st, 2009, 11:46 PM

Tags for this Thread