1

我正在使用 Apache MINA 2.0.4 为 android 开发应用程序。它在我测试过的所有版本上都运行良好,但在 HTC Desire 上是 2.2.2。

客户端设法连接到服务器,但是一旦服务器发送消息,我就会收到 NullPointerException:

04-16 13:45:25.992: E/EXCEPTION(18456): NETWORK
04-16 13:45:25.992: E/EXCEPTION(18456): org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.NullPointerException (Hexdump: 00 00 00 32 AC ED 00 05 73 72 01 00 25 63 6F 6D 2E 62 6F 6C 6C 73 2E 73 68 61 72 65 64 2E 77 77 77 2E 48 69 67 68 4C 65 76 65 6C 4D 65 73 73 61 67 65 78 70 28 70)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:251)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:46)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:796)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.core.filterchain.IoFilterAdapter.messageReceived(IoFilterAdapter.java:119)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireMessageReceived(DefaultIoFilterChain.java:426)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.core.polling.AbstractPollingIoProcessor.read(AbstractPollingIoProcessor.java:715)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:668)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:657)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$600(AbstractPollingIoProcessor.java:68)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1141)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
04-16 13:45:25.992: E/EXCEPTION(18456):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
04-16 13:45:25.992: E/EXCEPTION(18456):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
04-16 13:45:25.992: E/EXCEPTION(18456):     at java.lang.Thread.run(Thread.java:1102)
04-16 13:45:25.992: E/EXCEPTION(18456): Caused by: java.lang.NullPointerException
04-16 13:45:25.992: E/EXCEPTION(18456):     at java.io.ObjectStreamField.resolve(ObjectStreamField.java:351)
04-16 13:45:25.992: E/EXCEPTION(18456):     at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1863)
04-16 13:45:25.992: E/EXCEPTION(18456):     at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:826)
04-16 13:45:25.992: E/EXCEPTION(18456):     at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:2066)
04-16 13:45:25.992: E/EXCEPTION(18456):     at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:929)
04-16 13:45:25.992: E/EXCEPTION(18456):     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2285)
04-16 13:45:25.992: E/EXCEPTION(18456):     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2240)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.core.buffer.AbstractIoBuffer.getObject(AbstractIoBuffer.java:2215)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.filter.codec.serialization.ObjectSerializationDecoder.doDecode(ObjectSerializationDecoder.java:92)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.filter.codec.CumulativeProtocolDecoder.decode(CumulativeProtocolDecoder.java:178)
04-16 13:45:25.992: E/EXCEPTION(18456):     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:241)
04-16 13:45:25.992: E/EXCEPTION(18456):     ... 15 more

我正在使用 ObjectSerializationCodecFactory 并且无法弄清楚出了什么问题。我曾尝试在 Android 2.2 上使用“常规”Java 序列化并且效果很好。

这是连接的代码:

    NioSocketConnector tConnector = new NioSocketConnector();

    tConnector.setConnectTimeoutMillis(CONNECT_TIMEOUT);
    tConnector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
    tConnector.setHandler(new ClientHandler());

    try{
        ConnectFuture future = tConnector.connect(new InetSocketAddress(HOSTNAME, PORT));
        future.awaitUninterruptibly();
        mSession = future.getSession();
        Globals.hideDialog();
    }catch (RuntimeIoException e){
        Globals.hideDialog();
        Globals.showConnectionErrorDialog("Failed to connect to server");
    }

    // wait until the summation is done
    if(mSession != null)
        mSession.getCloseFuture().awaitUninterruptibly();
    tConnector.dispose();

在调用 messageReceived 之前,异常在处理程序中被捕获。

感谢您提供有关此异常的任何信息!

谢谢

4

1 回答 1

0

我认为 ClientHandler() 是接口。您需要尝试 BasicClientHandler()。

于 2012-04-16T12:52:12.957 回答