栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

jdk1.4java.net.url包

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

jdk1.4java.net.url包

我在从HttpRequest JavaDoc编译简单的阻止GET示例时遇到问题:

package org.example;

import java.io.IOException;

import java.net.URI;

import java.net.URISyntaxException;

import java.net.http.HttpRequest;

import java.net.http.HttpResponse;

import static java.net.http.HttpRequest.noBody;

import static java.net.http.HttpResponse.asString;

public class Http2 {

public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException {

HttpResponse response = HttpRequest

.create(new URI("http://www.infoq.com"))

.body(noBody())

.GET().response();

int responseCode = response.statusCode();

String responseBody = response.body(asString());

System.out.println(responseBody);

}

}

我得到package java.net.http does not exist使用JDK 9编译时错误:

{ jdk9 } » /cygdrive/c/Program Files/Java/jdk-9/bin/javac -d out/production -modulesourcepath org.example.module1/src/ -m org.example.module1

org.example.module1srcorg.example.module1orgexampleHttp2.java:6: error: package java.net.http does not exist

import java.net.http.HttpRequest;

^

org.example.module1srcorg.example.module1orgexampleHttp2.java:7: error: package java.net.http does not exist

import java.net.http.HttpResponse;

^

org.example.module1srcorg.example.module1orgexampleHttp2.java:9: error: package java.net.http does not exist

import static java.net.http.HttpRequest.noBody;

^

org.example.module1srcorg.example.module1orgexampleHttp2.java:9: error: static import only from classes and interfaces

import static java.net.http.HttpRequest.noBody;

^

org.example.module1srcorg.example.module1orgexampleHttp2.java:10: error: package java.net.http does not exist

import static java.net.http.HttpResponse.asString;

^

org.example.module1srcorg.example.module1orgexampleHttp2.java:10: error: static import only from classes and interfaces

import static java.net.http.HttpResponse.asString;

^

org.example.module1srcorg.example.module1orgexampleHttp2.java:14: error: cannot find symbol

HttpResponse response = HttpRequest

^

symbol: class HttpResponse

location: class Http2

org.example.module1srcorg.example.module1orgexampleHttp2.java:14: error: cannot find symbol

HttpResponse response = HttpRequest

^

symbol: variable HttpRequest

location: class Http2

org.example.module1srcorg.example.module1orgexampleHttp2.java:16: error: cannot find symbol

.body(noBody())

^

symbol: method noBody()

location: class Http2

org.example.module1srcorg.example.module1orgexampleHttp2.java:19: error: cannot find symbol

String responseBody = response.body(asString());

^

symbol: method asString()

location: class Http2

10 errors

使用命令行和IntelliJ会发生相同的错误。

我的模块没有问题,因为没有java.net.http的类可以编译并运行而没有任何问题。

知道发生了什么吗?

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/910318.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号