COMM_UP无法解析为变量

时间:2015-06-22 23:22:27

标签: java eclipse java-7

我是java的新手,我只是想为客户端编译示例: http://www.oracle.com/technetwork/articles/javase/index-139946.html

Answer::orderBy('created_at', 'desc')->groupBy('qid')->get();

当我在eclipse下使用java1.7.0-jdk编译代码时,我收到错误消息:

  

线程中的异常" main" java.lang.Error:未解析的编译   问题:COMM_UP无法解析为变量

据我了解,COMM_UP是在import java.io.IOException; import java.net.InetSocketAddress; import java.nio.CharBuffer; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; import java.util.Date; import java.text.SimpleDateFormat; import java.util.Locale; import java.io.PrintStream; import com.sun.nio.sctp.*; public class MultilingualDayTimeClient { static int SERVER_PORT = 3456; static int US_STREAM = 0; static int FR_STREAM = 1; public static void main(String[] args) throws IOException { InetSocketAddress serverAddr = new InetSocketAddress("localhost", SERVER_PORT); ByteBuffer buf = ByteBuffer.allocateDirect(60); Charset charset = Charset.forName("ISO-8859-1"); CharsetDecoder decoder = charset.newDecoder(); SctpChannel sc = SctpChannel.open(serverAddr, 0, 0); /* handler to keep track of association setup and termination */ AssociationHandler assocHandler = new AssociationHandler(); /* expect two messages and two notifications */ MessageInfo messageInfo = null; do { messageInfo = sc.receive(buf, System.out, assocHandler); buf.flip(); if (buf.remaining() > 0 && messageInfo.streamNumber() == US_STREAM) { System.out.println("(US) " + decoder.decode(buf).toString()); } else if (buf.remaining() > 0 && messageInfo.streamNumber() == FR_STREAM) { System.out.println("(FR) " + decoder.decode(buf).toString()); } buf.clear(); } while (messageInfo != null); sc.close(); } static class AssociationHandler extends AbstractNotificationHandler<PrintStream> { public HandlerResult handleNotification(AssociationChangeNotification not, PrintStream stream) { if (not.event().equals(COMM_UP)) { int outbound = not.association().maxOutboundStreams(); int inbound = not.association().maxInboundStreams(); stream.printf("New association setup with %d outbound streams" + ", and %d inbound streams.\n", outbound, inbound); } return HandlerResult.CONTINUE; } public HandlerResult handleNotification(ShutdownNotification not, PrintStream stream) { stream.printf("The association has been shutdown.\n"); return HandlerResult.RETURN; } } } 类型中定义的 我导入的是:

com.sun.nio.sctp.AssociationChangeNotification.AssocChangeEvent

为什么我无法复编?

问候

2 个答案:

答案 0 :(得分:0)

使用:

AssociationChangeNotification.AssocChangeEvent.COMM_UP

而不仅仅是COMM_UP来引用此值 - 它是enum类的内部类中的AssociationChangeNotification值,因此您必须以这种方式引用它(或使用更多进口)。

答案 1 :(得分:0)

感谢您的回答,

import com.sun.nio.sctp.AssociationChangeNotification.AssocChangeEvent;

没有工作。我认为greg给出了为什么这不起作用的答案:

  

它是AssociationChangeNotification类的内部类中的枚举值,因此您必须以这种方式引用它(或使用更多导入)。

使用:

AssociationChangeNotification.AssocChangeEvent.COMM_UP

的工作。 感谢