3

I am trying to use websockets in java and I am coming across this issue:

Cannot call method public final void package.ClientWebSocket#jettyOnMessage(byte[], int, int) with args: [[B, java.lang.Integer, java.lang.Integer]

Here is the code snippet that is actually being called

 @OnWebSocketMessage
 public final void jettyOnMessage(final byte[] data, final int offset, final int length) {
     onMessage(ByteBuffer.wrap(data, offset, length));
 }

Here is there documentation that describes what the method signature should be:

 * <u>Binary Message Versions</u>
 * <ol>
 * <li><code>public void methodName(byte buf[], int offset, int length)</code></li>
 * <li><code>public void methodName({@link Session} session, byte buf[], int offset, int length)</code></li>
 * <li><code>public void methodName(InputStream stream)</code></li>
 * <li><code>public void methodName({@link Session} session, InputStream stream)</code></li>
 * </ol>
 */

As you can tell I am using the first version of the call. What am I doing wrong?

Edit1:

I made the method non final and that did not change anything.

4

1 回答 1

4

如果有人遇到类似的异常,我会发现问题。

问题是我的一个方法在内部抛出了一个未捕获的异常。

如果您将整个代码包装在尝试中,您可以完全避免此异常并找到它被抛出的真正原因。

修复问题的代码:

@OnWebSocketMessage
public final void jettyOnMessage(final byte[] data, final int offset, final int length) {
    try {
        onMessage(ByteBuffer.wrap(data, offset, length));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

onMessage 可能引发异常的地方

我的情况是它最终成为 ArrayOutOfBoundsException 因为我愚蠢地做 list.get(list.size());

它的小事让你。

于 2015-01-07T22:10:02.077 回答