There are two commons scenarios for NoSuchMethodError
:
1) API method/s you have used in your code is different than run time jar version
2) Jar (X) you have used has dependency on Jar (Y)--> But you have incompatible Jar (Y) at runtime.
EDIT:
For #1 how can I prevent it?
This is easy to handle case, add a jar to lib and add same jar in compiler path (add library section if eclipse)
For #2 why does it happen?
This happens if you have downloaded Jar X which in turn requires jar Y, so you will go internet and download, but doesn't care much about which version of Y is compatible with X.
How can we prevent this case?
Read readme.txt from Jar X and download supported Y version.
Any way to prevent both?
There is no bullet answer for this, you need to properly read the documentation instead of simply download and put in classpath.