Bart g
Bart g

Reputation: 585

Simple JOptionPane.showMessage();

This is the code of a button that when is clicked it searches for a user id in a database and displays name, last name and hours. What I want to do is to pop up a message(JOptionPane.showMessage()) that shows the time when the user clocks in/out so what I thought I could do is to add "JOptionPane.showMessage()" to do exactly that, but when I put this code(no matter where) there is a red line under "showMessage" and an error message saying:

==cannot find symbol
==symbol: method showMessage(java.lang.String)
==location:class javax.swing.JOptionPane

Not sure what that means. Any help very much appreciated. Thank you.

private void clockInOutActionPerformed(java.awt.event.ActionEventevt){   

    // TODO add your handling code here:
    try{
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,  ResultSet.CONCUR_UPDATABLE);
           String sql = "SELECT * FROM Students WHERE STUDENTID = ?";
        PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setInt(1, Integer.parseInt(jTextField1.getText()));
        ResultSet rs = pstmt.executeQuery();

        if(rs.next()){
            String first = rs.getString(2);
            String last = rs.getString(3);
            String hours = rs.getString(6);

            fName.setText(first);
            lName.setText(last);
            tHours.setText(hours);
        }       
    }
    catch(SQLException err){
        JOptionPane.showMessageDialog(Student.this, err.getMessage());
    }
}

Upvotes: 2

Views: 2910

Answers (2)

Isuru
Isuru

Reputation: 8193

There are couple of issues I want to point out in this code

private void clockInOutActionPerformed(java.awt.event.ActionEvent evt){

there is a missing space between argument type and argument name

JOptionPane.showMessageDialog(Student.this, err.getMessage());

there are three override methods for showMessageDialog and for all of them first argument should be type of java.awt.Component so I assume your Student is extending java.awt.Component and it contains the above clockInOutActionPerformed method.

Otherwise code want compile.

Any way what is meant by the message

Other than that, I cant reproduce the similar error you are getting.

I think you need to check the jdk version you are using.JOptionPane may not be available for jdk version you are using.

Upvotes: 1

Gori
Gori

Reputation: 361

Probably you misspelled the class name or you didn't import the class name, check that and try again. And also what Andrew Said.

In case you are using the IDE Eclipse if you press Ctrl+Shift+o (letter O) it imports everything automatically for you.

Hope it helps.

Upvotes: 1

Related Questions