(databaseForm.java)
public class databaseForm extends javax.swing.JFrame {
/** * Creates new form databaseForm */ String imgPth = null; public databaseForm() { initComponents(); } private void jLabelCloseMouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: System.exit(0); } private void jLabelMinMouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: this.setState(JFrame.ICONIFIED); } private void jButtonBrowseActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Myfunc mf = new Myfunc(); imgPth = mf.browseImage(jLabelDataPic); System.out.println(imgPth); } private void jButtonAddDataActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: String snumber = jTextFieldSNumber.getText(); String fname = jTextFieldFName.getText(); String lname = jTextFieldLName.getText(); String gender = jComboBoxGender.getSelectedItem().toString(); String course = jComboBoxCourse.getSelectedItem().toString(); String year = jComboBoxYear.getSelectedItem().toString(); String section = jComboBoxSection.getSelectedItem().toString(); String address = jTextAreaAddress.getText();
byte[] img = null; try { Path pth = Paths.get(imgPth); img = Files.readAllBytes(pth);
data d = new data(0, snumber, fname, lname, gender, course, year, section, img, address, 0); }
(data.java)
public class data {
private int cid; private String SNumber; private String FName; private String LName; private String Gender; private String Course; private String Year; private String Section; private byte Image; private String Address; private int uid; // Alt Insert // to generate constructor & getters & setters public data() {} public data(int cid, String SNumber, String FName, String LName, String Gender, String Course, String Year, String Section, byte Image,
String Address, int uid) { this.cid = cid; this.SNumber = SNumber; this.FName = FName; this.LName = LName; this.Gender = Gender; this.Course = Course; this.Year = Year; this.Section = Section; this.Image = Image; this.Address = Address; this.uid = uid; }
public int getCid() { return cid; } public void setCid(int cid) { this.cid = cid; } public String getSNumber() { return SNumber; } public void setSNumber(String SNumber) { this.SNumber = SNumber; } public String getFName() { return FName; } public void setFName(String FName) { this.FName = FName; } public String getLName() { return LName; } public void setLName(String LName) { this.LName = LName; } public String getGender() { return Gender; } public void setGender(String Gender) { this.Gender = Gender; } public String getCourse() { return Course; } public void setCourse(String Course) { this.Course = Course; } public String getYear() { return Year; } public void setYear(String Year) { this.Year = Year; } public String getSection() { return Section; } public void setSection(String Section) { this.Section = Section; } public byte getImage() { return Image; } public void setImage(byte Image) { this.Image = Image; } public String getAddress() { return Address; } public void setAddress(String Address) { this.Address = Address; } public int getUid() { return uid; } public void setUid(int uid) { this.uid = uid; } }
CodePudding user response:
In your constructor, public data(int cid, String SNumber, String FName, String LName, String Gender, String Course, String Year, String Section, byte Image,String Address, int uid)
you are expecting Image
to be of type byte but passing byte array byte[] img = null;
Change the parameter type for Image
attribute in Data class to byte[]