Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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 7,尝试并捕获问题?ubuntueclipseide_Java_Ubuntu - Fatal编程技术网

Java 7,尝试并捕获问题?ubuntueclipseide

Java 7,尝试并捕获问题?ubuntueclipseide,java,ubuntu,Java,Ubuntu,您好,我对下面的代码有一些问题。try-and-catch块在我的IDE中的try行上有一个红色的X,告诉我遇到了一个“(”,但应该是一个“{”),我是否遗漏了什么?我可能有什么问题 import java.io.IOException; import java.net.InetSocketAddress; import java.net.StandardSocketOptions; import java.nio.ByteBuffer; import java.nio.channels.Asy

您好,我对下面的代码有一些问题。try-and-catch块在我的IDE中的try行上有一个红色的X,告诉我遇到了一个“(”,但应该是一个“{”),我是否遗漏了什么?我可能有什么问题

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.StandardSocketOptions;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/** * * @author Apress */

public class FutureForm 
{
public static void main(String[] args) 
{
    final int DEFAULT_PORT = 5555;
    final String IP = "127.0.0.1";
    // v-This parenthesis should be a bracket it says??
    try( AsynchronousServerSocketChannel asynchronousServerSocketChannel = AsynchronousServerSocketChannel.open()) 
    {
        if (asynchronousServerSocketChannel.isOpen()) 
        {
            asynchronousServerSocketChannel.bind(new InetSocketAddress(IP, DEFAULT_PORT));
            System.out.println("Waiting for connections ...");
            while (true) 
            {
                Future<AsynchronousSocketChannel> asynchronousSocketChannelFuture = asynchronousServerSocketChannel.accept();
                try (AsynchronousSocketChannel asynchronousSocketChannel = asynchronousSocketChannelFuture.get()) 
                {
                    System.out.println("Incoming connection from: " + asynchronousSocketChannel.getRemoteAddress());
                    final ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
                    while (asynchronousSocketChannel.read(buffer).get() != -1) 
                    {
                        buffer.flip();
                        asynchronousSocketChannel.write(buffer).get();
                        if (buffer.hasRemaining()) 
                            buffer.compact();
                        else 
                            buffer.clear();
                    }
                    System.out.println(asynchronousSocketChannel.getRemoteAddress() + " was successfully served!");
                } 
                catch (IOException || InterruptedException || ExecutionException ex) 
                {
                    System.err.println(ex);
                }
            }
        } 
        else 
        {
            System.out.println("The asynchronous server-socket channel cannot be opened!");
        }
    } 
    catch (IOException ex) 
    {
        System.err.println(ex);
    }
}
}
import java.io.IOException;
导入java.net.InetSocketAddress;
导入java.net.StandardSocketOptions;
导入java.nio.ByteBuffer;
导入java.nio.channels.AsynchronousServerSocketChannel;
导入java.nio.channels.AsynchronousSocketChannel;
导入java.util.concurrent.ExecutionException;
导入java.util.concurrent.Future;
/*****作者Apress*/
公共类未来表单
{
公共静态void main(字符串[]args)
{
最终int默认_端口=5555;
最终字符串IP=“127.0.0.1”;
//这个括号应该是一个括号,上面写着??
try(AsynchronousServerSocketChannel AsynchronousServerSocketChannel=AsynchronousServerSocketChannel.open())
{
if(异步服务器socketchannel.isOpen())
{
asynchronousServerSocketChannel.bind(新的InetSocketAddress(IP,默认_端口));
System.out.println(“等待连接…”);
while(true)
{
Future asynchronousSocketChannelFuture=asynchronousServerSocketChannel.accept();
try(AsynchronousSocketChannel AsynchronousSocketChannel=asynchronousSocketChannelFuture.get())
{
System.out.println(“来自:“+asynchronousSocketChannel.getRemoteAddress()”的传入连接);
final ByteBuffer buffer=ByteBuffer.allocateDirect(1024);
while(异步socketchannel.read(buffer.get()!=-1)
{
flip();
异步socketchannel.write(buffer.get();
if(buffer.haslaining())
buffer.compact();
其他的
buffer.clear();
}
System.out.println(异步socketchannel.getRemoteAddress()+“已成功送达!”);
} 
捕获(IOException | | InterruptedException | | ExecutionException ex)
{
系统错误打印项次(ex);
}
}
} 
其他的
{
System.out.println(“异步服务器套接字通道无法打开!”);
}
} 
捕获(IOEX异常)
{
系统错误打印项次(ex);
}
}
}

不确定这是否是警告的原因,但您的multicatch中有一个语法错误:您只需要使用单管道

catch (IOException | InterruptedException | ExecutionException ex)

不确定这是否是警告的原因,但您的multicatch中有一个语法错误:您只需要使用单管道

catch (IOException | InterruptedException | ExecutionException ex)

验证您是否已在Java>Compiler“Compiler compliance level”下的首选项中为Java 1.7配置了工作区


如果没有帮助,请检查Java编译器下的项目属性,该属性不应具有特定于项目的设置,或已配置1.7。

请验证您是否已在Java>编译器“编译器符合性级别”下的首选项中为Java 1.7配置了工作区


如果没有帮助,请检查Java编译器下的项目属性,它不应该有项目特定的设置,或者配置了1.7。

我有使用Java 1.7.0 openjdk的项目设置…我确实使用Java 7进行了设置,但两个都给出了相同的错误。还有其他想法吗?你是指下面的项目设置吗r“Java构建路径”:“库”或“Java编译器”:“JDK遵从性”嗯,我没有。但是现在我看了Java编译器,JDK合规性,它只允许我将它设置为1.6,而不是1.7。我没有选择将它设置为1.7。你有什么版本的Eclipse?我在去年的Indigo发行版中看到了1.7。版本3.7.0。我将尝试看看是否有任何更新我的项目设置可以使用java 1.7.0 openjdk…我确实使用了Java 7,但它们都给出了相同的错误。还有其他想法吗?您是指“Java构建路径”:“库”下的项目设置,还是指“Java编译器”:“JDK合规性”嗯,我没有。但是现在我看了Java编译器,JDK compliance,它只允许我将它设置为1.6,而不是1.7。我没有选择将它设置为1.7。你有什么版本的Eclipse?我在去年的Indigo版本3.7.0中看到了1.7。我将尝试看看是否有updates@BumSkeeter那么它要么是一个conf配置问题或错误。根据我建议的更正,您的代码可以在我的计算机(Windows/Netbeans)上编译并运行良好。谢谢……我想我会设法找一个同学来帮忙。我们使用java 6的时间最长,但我想java 7中没有。因此我们必须升级。@Bumsketer那么这要么是配置问题,要么是错误。根据我提出的更正,您的代码在我的机器(Windows/Netbeans)上编译并运行良好.谢谢你…我想我会试着找一个同学来帮忙的。我们使用java 6的时间最长,但我想java 7中没有。所以我们必须升级。