Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 检查字符串时出现NoTouchElementException_Java_Http_Nosuchelementexception - Fatal编程技术网

Java 检查字符串时出现NoTouchElementException

Java 检查字符串时出现NoTouchElementException,java,http,nosuchelementexception,Java,Http,Nosuchelementexception,我目前正在编写一个基本的http服务器。如果协议版本为1.1且没有主机行,则需要的功能之一是显示400错误 我有以下扫描器(行是保存请求文件的数组) 然后我有下面的if语句,用来检查hostline是否为空 if ( protocol.equals("HTTP/1.1") && hostline.isEmpty() ) { String reply="HTTP/1.0 400 Bad Request\r\n" + "Connection: close\r

我目前正在编写一个基本的http服务器。如果协议版本为1.1且没有主机行,则需要的功能之一是显示400错误

我有以下扫描器(行是保存请求文件的数组)

然后我有下面的if语句,用来检查hostline是否为空

if ( protocol.equals("HTTP/1.1") && hostline.isEmpty() ) {
String reply="HTTP/1.0 400 Bad Request\r\n" +
             "Connection: close\r\n" +
             "Content-Type: " + contentType + "\r\n" +
             datestr +
             "<h1>HTTP/1.0 400 Bad Request</h1>\r\n";
outs.write(reply.getBytes()); }
如果没有更多的令牌可用,则抛出NoTouchElementException。因此,您应该首先检查是否有更多具有

如果没有更多的令牌可用,则抛出NoTouchElementException。因此,您应该首先检查是否有更多具有


正如你所说,可能是“没有主机线”。加一个警卫怎么样

String hostline = scn2.hasNext() ? scn2.next() : ""

正如你所说,可能是“没有主机线”。加一个警卫怎么样

String hostline = scn2.hasNext() ? scn2.next() : ""

您对程序的输入是什么?它是我们使用netcat进行测试时来自请求文件的数据。我用来测试这个if的是:GET/tiny.html HTTP/1.1 Host:Connection:close你的例子对我很有用。确保您的输入正确。您对程序的输入是什么?这是我们使用netcat测试时从请求文件中获取的数据。我用来测试这个if的是:GET/tiny.html HTTP/1.1 Host:Connection:close你的例子对我很有用。确保你的输入正确这就是我要找的。多谢了,这正是我要找的。谢谢
if (scn.hasNext()) {
    variable = scn.next();
}
String hostline = scn2.hasNext() ? scn2.next() : ""