I am referring Validate X.509 certificate against CA in Java this post.
My implementation of checkServerTrusted
look like:
@Override
It doesn't make sense to try to verify all the certificates in the chain against a single public key. Most of them won't have been signed by it, so the procedure is bound to fail, and throw an exception to the caller.
You need to review what it is you're supposed to do in this method. See the Javadoc. You're trying to establish a certificate path from this chain to a trusted root certificate.
In this case the trusted root certificate is presumably the one you loaded from the file.
What you should be doing therefore is:
It isn't clear to me whether you need to also verify each certificate in the chain, except the last, with the next one's public key, but it can't hurt.
EDIT You should also implement the suggestion in this answer.