JAVA_HOME is set to an invalid directory:

androidcordovajava

I have set JAVA_HOME in my system C:\Program Files\Java\jdk1.8.0_
131\bin;
and I am trying to run cordova command( cordova build ) on command prompt, but I'm getting the error bellow. I have tried all the ways, but not able to resolve this issue:

ERROR: JAVA_HOME is set to an invalid directory: C:\Program
Files\Java\jdk1.8.0_ 131\bin;

Please, set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Best Solution

You should set it with C:\Program Files\Java\jdk1.8.0_12.

\bin is not required.