I'm trying to use HTTP GET and POST in Java but I can't import java.net.http
. I have very little knowledge about this area, do I need to install something?
Asked
Active
Viewed 8,267 times
2

Shane Bishop
- 3,905
- 4
- 17
- 47

Insanit
- 37
- 1
- 8
-
What Java version are you using? And how are you importing whatever class you're trying to import? (since `java.net.http` is a package, not a class) – Federico klez Culloca Jan 05 '21 at 16:27
-
Please add an example to show how you are importing the package. – Soroosh Sarabadani Jan 05 '21 at 16:28
-
Could you check which version of Java do you use? The package java.net.http was introduced in Java 11 – Andres Sacco Jan 05 '21 at 16:44
-
I don't know which java version I'm using , an example would be import java.net.http.HttpClient. I'm using Eclipse IDE – Insanit Jan 05 '21 at 16:47
-
You can check which version of Java do you use on Eclipse. Preferences -> Java -> Compiler (>11) and Preferences -> Java -> Installed JRE – Andres Sacco Jan 05 '21 at 16:50
-
It says jre1.8.0_261 – Insanit Jan 05 '21 at 16:57
-
1You need to install Java 11 or up – Andres Sacco Jan 05 '21 at 17:00
-
I installed jdk 11 but I still have the same problem – Insanit Jan 05 '21 at 17:09
-
1@Insanit you should also configure your OS and/or IDE to use it. – Federico klez Culloca Jan 05 '21 at 17:09
-
I configured both the Installed JREs and Execution Environments on Eclipse but it still gives me a warning saying current version is 1.8 – Insanit Jan 05 '21 at 17:14
-
Open your pom file and check which version of Java appears – Andres Sacco Jan 05 '21 at 17:16
-
Not sure if it's the right one but I found -vm C:\Program Files\Java\jre1.8.0_261\bin\server\jvm.dll in the Configuration – Insanit Jan 05 '21 at 17:27
-
[Check the answer to this question](https://stackoverflow.com/questions/12588537/how-to-change-jdk-version-for-an-eclipse-project) – Andres Sacco Jan 05 '21 at 17:30
1 Answers
3
The problem is connected with the version of Java/JRE that exist in your system because the package "java.net.http" was included in Java 11 or up.
Try to download a new version of java from one of these sites Oracle JDK 11 or Open JDK
After installing the new version of Java check that Eclipse uses the correct one. To do this in your Eclipse go to Preferences -> Java -> Compiler and select 11, also go to Preferences -> Java -> Installed JRE and add the new JRE

Andres Sacco
- 650
- 3
- 13
-
1Thanks I got it to work after changing the line under -vm in eclipse.ini to the correct latest version of java that I installed. – Insanit Jan 05 '21 at 17:32
-
-
@AndresSacco if im using Android Studio 2020.3.1 Patch 2, Wher i can install JRE? – renaldyks Apr 01 '22 at 08:28