Click here to Skip to main content
15,887,341 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Java
private void jAddActionPerformed(java.awt.event.ActionEvent evt) {

String code = jCode.getText();
String registrationNumberText = jRegistrationNumber.getText();
String barcodeText = jBarcode.getText();
String maincharName = jMaincharName.getText();
String title = jTitle.getText();
String version = jVersion.getText();
String size = jSize.getSelectedItem().toString();

if (code.isEmpty() || registrationNumberText.isEmpty() || barcodeText.isEmpty()) {
    // Handle the case where any of the required fields are empty
    System.out.println("Please fill in all the required fields.");
    return; // Exit the method to prevent further execution
}

int registrationNumber;
int barcode;

try {
    registrationNumber = Integer.parseInt(registrationNumberText);
    barcode = Integer.parseInt(barcodeText);
} catch (NumberFormatException e) {
    // Handle the case where the input strings cannot be parsed as integers
    System.out.println("Invalid input for registration number or barcode.");
    e.printStackTrace();
    return; // Exit the method to prevent further execution
}

Collection collect = new Collection(code, registrationNumber, barcode, maincharName, title, version, size);
CollectionRepository cr = new CollectionRepository();
cr.insertProduct(collect);
jCode.setText("");
jRegistrationNumber.setText("");
jBarcode.setText("");
jMaincharName.setText("");
jTitle.setText("");
jVersion.setText("");
jSize.setSelectedItem("");

view();

}


What I have tried:

private void jAddActionPerformed(java.awt.event.ActionEvent evt) {                                     
                                   
    String code = jCode.getText();
    String registrationNumberText = jRegistrationNumber.getText();
    String barcodeText = jBarcode.getText();
    String maincharName = jMaincharName.getText();
    String title = jTitle.getText();
    String version = jVersion.getText();
    String size = jSize.getSelectedItem().toString();

    if (code.isEmpty() || registrationNumberText.isEmpty() || barcodeText.isEmpty()) {
        // Handle the case where any of the required fields are empty
        System.out.println("Please fill in all the required fields.");
        return; // Exit the method to prevent further execution
    }

    int registrationNumber;
    int barcode;

    try {
        registrationNumber = Integer.parseInt(registrationNumberText);
        barcode = Integer.parseInt(barcodeText);
    } catch (NumberFormatException e) {
        // Handle the case where the input strings cannot be parsed as integers
        System.out.println("Invalid input for registration number or barcode.");
        e.printStackTrace();
        return; // Exit the method to prevent further execution
    }

    Collection collect = new Collection(code, registrationNumber, barcode, maincharName, title, version, size);
    CollectionRepository cr = new CollectionRepository();
    cr.insertProduct(collect);
    jCode.setText("");
    jRegistrationNumber.setText("");
    jBarcode.setText("");
    jMaincharName.setText("");
    jTitle.setText("");
    jVersion.setText("");
    jSize.setSelectedItem("");  
        
    view();

    }
Posted
Updated 11-Aug-23 21:46pm
v4
Comments
Richard MacCutchan 11-Aug-23 3:36am    
Just dumping all your code, badly formatted, twice, is not the way to get help here. Please use the Improve question link above, and edit your question to show just the code that causes the problem (and only one copy), and full details of what is happening. As it stands no one is even going to try.
Dave Kreskowiak 11-Aug-23 23:39pm    
I'm sure it makes perfect sense to you, but for the rest of us trying to look at this, what do you mean by "result is null"?
jann manalastas 11-Aug-23 23:56pm    
the product of my code is an inventory collection, so the table elements that should show is code, registrationNumber, barcode, maincharName, title, version, size. And when you put value on those elements it should show under those elements like this

code.....registrattion number....barcode....mcname....title....version....size
a-1...............0.....................2223333.........jeff..........game........original....big


but instead it show's like this



code.....registrattion number....barcode....mcname....title....version....size
a-1...............0...................2223333.........null..........game........original.....null

*the dots represents the spaces*
Richard MacCutchan 12-Aug-23 3:45am    
So you need to find out why the barcode column is null. But since that is somewhere in your data it is not something anyone here can do for you.
Andre Oosthuizen 12-Aug-23 5:08am    
This is unfortunately what happens when you copy and paste code from ChatGPT without understanding what the code is suppose to do. It is great using ChatGPT but you need to look at what the AI returned, check each line, research certain methods until you understand the code, you will then know exactly where any issues lie and you can correct it. ChatGPT DOES NOT return 100% correct code as it wants you to believe.

Thing to research for instance to have a better understanding will be -
parseInt
NumberFormatException
printStackTrace
Collection and CollectionRepository etc.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900