I had same exception while trying to install hadoop on my mac and I solved the problem by explicitly defining java home at yarn-env.sh and hadoop-env.sh files
so go to etc/hadoop and edit hadoop-env.sh and yarn-env.sh files with explicit java home directory.
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk...
good luck!