简体   繁体   中英

I'm facing an error with jcalender code in netbeans

I'm making an airplane reservation system with java and when I run the code, it results into an error.

The error I'm receiving is:

"Incompatible types: Date cannot be converted into calendar."

And it appears at dateChooserCombo1.setSelectedDate(Calendar.getInstance().getTime()); and at dt=dateChooserCombo1.getSelectedDate(); What can I do to eliminate this errors

 try
    {
        Class .forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/a_r_s","root","");
        dateChooserCombo1.setSelectedDate(Calendar.getInstance().getTime());
        sdf= new SimpleDateFormat("dd-MM-yyyy");
    }
    catch(Exception e)
    {
     System.out.println(e.getMessage());
    }
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    final Object[] columnNames=new String[] {"Date","Flight Name","Departure Time","BC Seats Available","XC Seats Available","EC Seats Available"};
    DefaultTableModel dtm=new DefaultTableModel(columnNames,0);        
    origin=jComboBox3.getSelectedItem().toString();
    target=jComboBox4.getSelectedItem().toString();
    fclass=jComboBox1.getSelectedItem().toString();

    dt=dateChooserCombo1.getSelectedDate();      
    SimpleDateFormat sdf1= new SimpleDateFormat("yyyy-MM-dd");
    strdtver2=(String) sdf1.format(dateChooserCombo1.getSelectedDate());
    /**************************************
    //Seven days flight calendar processing
    **************************************/
    dt7=dateChooserCombo1.getSelectedDate();
    Calendar cal = Calendar.getInstance();
    cal.setTime(dt7);
    cal.add(Calendar.DATE, 7);
    dt7 = cal.getTime();
    strdtver3=(String) sdf1.format(dt7);

Date and Calendar are not compatible types. You must convert between them:

Date date= new Date();
Calendar cal = Calendar.getInstance(); 
cal.setTime(date);

Also make sure you use the correct Java Date type: java.util.Date and not java.sql.Date .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM