Здравствуйте, у меня возникли проблемы с кодом ниже. Попробовать и поймать блоки имеют красный крестик на Ьгу линии в моем IDE говорил мне, что «(» встречалось, а «{» было ожидаемо. Я пропускаю что-то? Что может быть моя проблема?Java 7, попробовать и уловить проблемы? Ubuntu Eclipse IDE
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);
}
}
}
У меня есть настройки моего проекта для использования java 1.7.0 openjdk ... У меня было это с помощью Java 7, но оба они все равно дают ту же ошибку. Любые другие идеи ..? –
Вы имеете в виду настройки проекта в разделе «Путь сборки Java»: «Библиотеки» или «Компилятор Java»: «Соответствие JDK»? –
Hm. Я не был. Но теперь, когда я смотрю на компилятор Java, JDK-совместимость, я разрешу установить его только на 1.6, а не на 1.7. У меня нет возможности установить его в 1.7. –