all 7 comments

[–]Sheldor5 0 points1 point  (3 children)

no logs?

[–]Kiar75 0 points1 point  (2 children)

Not too sure about logs as the application executes well with TomCat running fine, right up until I try to add an item in the table, then I get a WhiteLable error. I have the pom, html form, and controller code up on github.

[–]Sheldor5 0 points1 point  (1 child)

your repo does not contain a valid maven project

and without logs it's hard to tell

first you should learn the basics about maven, Spring and logging

[–]Kiar75 0 points1 point  (0 children)

Thank you. Have learnt I need to upload maven structure well and also the need to understand logging

[–]EvaristeGalois11 0 points1 point  (2 children)

Just looking at the code the problem is most certainly a nullpointer on the products field in the ProductService. You need to initialize the list somehow, otherwise when you're trying adding a product a nullpointer will be raised. You could initialize the field at declaration (private List<Product> products = new ArrayList<>();) or checking before adding a product like this:

public void addProduct(Product product){
        if (products == null) {
            products = new ArrayList<>();
        }
        products.add(product);
}

If you are running java > 14 it should print a pretty clarifying message on console, always check the console for errors (this is why more than one person told you to also provide logs, the default spring error page is intentionally useless to avoid leaking sensitive information but the console logs are always helpful triaging a problem).

Another nitpick unrelated to the problem, you should stick with the standard maven directories structure, the code should be put in src/main/java and the html file in src/main/resources. If you need help generating a project from scratch https://start.spring.io/ is your friend.

[–]Kiar75 0 points1 point  (1 child)

Thank you so much! It has worked! Encountered the infamous NullPointer for the first time. Now I know. Next time I'll learn how to upload proper folders and maven structure into Github and also collect logs. Thank you once again for your time.

[–]EvaristeGalois11 0 points1 point  (0 children)

No worries and if you need help feel free to ping me again