which OperatingSystem you are working on? If its on ubuntu then open a terminal, move to the project(your ionic2 project) folder and then set that JAVA_HOME variable
I have ionic 3 and I am on ubuntu
In .profile file I have set export JAVA_HOME=$JAVA_HOME:/usr/lib/jvm/java-8-oracle
ionic cordova build android is working fine
but ionic cordova run android is throwing the below error
UILD SUCCESSFUL
Total time: 1.323 secs
Built the following apk(s):
/var/www/html/ionic/myApp/platforms/android/build/outputs/apk/android-debug.apk
ANDROID_HOME=/opt/android-sdk/
JAVA_HOME=/usr/lib/jvm/java-8-oracle
No target specified and no devices found, deploying to emulator
Error: No emulator images (avds) found.
Download desired System Image by running: /opt/android-sdk/tools/android sdk
Create an AVD by running: /opt/android-sdk/tools/android avd
HINT: For a faster emulator, use an Intel System Image and install the HAXM device driver
[ERROR] Cordova encountered an error.
You may get more insight by running the Cordova command above directly.
[ERROR] An error occurred while running cordova run android (exit code 1).