4

I restarted and invalided caches

Here are my configs

cat /etc/environment 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/lib/jvm/java-7-oracle/jre/bin/java"

~$whereis java
java: /usr/bin/java /usr/bin/X11/java /usr/share/java /usr/share/man/man1/java.1.gz
~$ which java
/usr/bin/java


~$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 Aug 23 14:40 /usr/bin/java -> /etc/alternatives/java
~$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 39 Aug 23 14:40 /etc/alternatives/java -> /usr/lib/jvm/java-7-oracle/jre/bin/java

I read this to produce the above output. I continuously receive the red Intellij IDEA icon on my Hello.java file with contents of:

public class Hello {
    public static void main(String[] args){
        System.out.println("Hello World");
    }
}

Despite successfully running the program from the command line as such:

$ javac Hello.java 
$ java Hello 
Hello World

Here is the Java SDK path set on Intellij IDEA settings (Ctrl+Alt+Shift+S) /usr/lib/jvm/java-7-oracle

Here are the contents of my directory (named Hello) Hello.iml file:

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
    </content>
    <orderEntry type="jdk" jdkName="1.7 (1)" jdkType="JavaSDK" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>

I previously removed all JDK instances via this and I am certain there is only one Java JDK installed. I re-installed Java via this

What am I doing wrong? Any insight Please? Thank you

Community
  • 1
  • 1
phillipsK
  • 1,466
  • 5
  • 29
  • 43
  • Open the project settings and tell IntelliJ which JDK you want it to use. There should only be one, according to your description. – duffymo Aug 23 '15 at 19:15
  • Please note I also had to remove my Hello.java file and left click re-insert as a `Java Class` – phillipsK Aug 24 '15 at 10:05

1 Answers1

5

Inside Intellij you have to setup the JDK you want to use for the project. This is different from Eclipse that picks up the JDK by the default. OTOH, you have more flexibility to have multiple projects with different JDK (1.5, 1.7, 1.8, e.g.)

Follow the instructions here: How do I change the IntelliJ IDEA default JDK?

Community
  • 1
  • 1
eribeiro
  • 572
  • 3
  • 7