nus-cs2103-AY1718S1 / forum

Discussion Forum
5 stars 0 forks source link

Null Pointer Exception When Changing Image Filepath #185

Closed charlesgohck closed 7 years ago

charlesgohck commented 7 years ago

I am currently working on avatar buttons that will change the default image (set via FXML) into the user set image. However, this seems to be giving me NullPointerExceptions, which I am sure is coming from the connection between MainWindow --> PersonListPanel --> PersonCard. Has anyone encountered a similar issue and has managed to fix it successfully? Any advice is appreciated :)

This is my implementation (excluding the setter connection between PersonListPanel and MainWindow): screen shot 2017-11-04 at 10 57 44 am

This is the button ("Avatar") that calls the handler:

screen shot 2017-11-04 at 11 03 32 am
tshradheya commented 7 years ago

Any idea which line in the getNewAvtar() is giving the nullPointerException?

charlesgohck commented 7 years ago

It seems that my getNewAvatar() is returning a null value. Either that or Filechooser is not executing properly

damithc commented 7 years ago

@tshradheya didn't you implement an avatar feature? I remember someone mentioned an avatar feature here before. @charlesgoh you should be able to find the exact line causing the NPE from the stack trace.

tshradheya commented 7 years ago

@damithc I implemented something similar to avatar, but I avoided using a FileChooser due to OS difference(only later I realized the problem was with JFileChooser), and I am assuming that could be the reason for the null pointer.

@charlesgoh On doing some research I found out that showOpenDialog() doesn't allow any further code to be executed until the file chooser is closed(either after selecting[returns file object] or after canceling[returns null]).

So it will help if you know at what stage the NullPointerExcpetion is thrown( before filechooser dialog opens or after you have closed it)