0

My Netty communications classes work fine in a standard Java application but when I run them in an Android application I get a NullPointerException.

My question is if any Netty experts could point in the right direction for resolving this. Is it an incompatibility issue issue with Android or can you see anything in the stack trace that might indicate what I may be doing wrong?

I am using netty-3.4.0.Final.jar

I have added the internet permission to the AndroidManifest.xml.
I have verified that I can successfully connect to the server using just raw socket (without Netty) in the android app.

After I call bootstrap.connect() I can suspend execution at breakpoints in two threads. One in exceptionCaught() and one in channelClosed().

The stack track below is from exception exceptionCaught().

The full source from this project is located on codeplex in the elvemobileandroid project.

I believe I actually saw the Android project work once which might indicate that the exception is not always thrown. Unfortunately I have not been able to get it to work again (even though I have made no project changes).

Thread [<1> main] (Suspended (breakpoint at line 172 in UptimeClientHandler))   
    UptimeClientHandler.exceptionCaught(ChannelHandlerContext, ExceptionEvent) line: 172    
    UptimeClientHandler(SimpleChannelUpstreamHandler).handleUpstream(ChannelHandlerContext, ChannelEvent) line: 117 
    DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline$DefaultChannelHandlerContext, ChannelEvent) line: 564    
    DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(ChannelEvent) line: 792    
    ReadTimeoutHandler(SimpleChannelUpstreamHandler).exceptionCaught(ChannelHandlerContext, ExceptionEvent) line: 143   
    ReadTimeoutHandler(SimpleChannelUpstreamHandler).handleUpstream(ChannelHandlerContext, ChannelEvent) line: 117  
    DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline$DefaultChannelHandlerContext, ChannelEvent) line: 564    
    DefaultChannelPipeline.sendUpstream(ChannelEvent) line: 559 
    Channels.fireExceptionCaught(Channel, Throwable) line: 533  
    NioClientSocketPipelineSink.connect(NioClientSocketChannel, ChannelFuture, SocketAddress) line: 152 
    NioClientSocketPipelineSink.eventSunk(ChannelPipeline, ChannelEvent) line: 97   
    DefaultChannelPipeline.sendDownstream(ChannelEvent) line: 574   
    Channels.connect(Channel, SocketAddress) line: 642  
    NioClientSocketChannel(AbstractChannel).connect(SocketAddress) line: 204    
    ClientBootstrap.connect(SocketAddress, SocketAddress) line: 230 
    ClientBootstrap.connect(SocketAddress) line: 183    
    ClientBootstrap.connect() line: 154 
    UptimeClient.run() line: 94 
    CommunicationTest.test() line: 32   
    ElveMobileActivity.onCreate(Bundle) line: 25    
    Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1047   
    ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2627  
    ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2679   
    ActivityThread.access$2300(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 125 
    ActivityThread$H.handleMessage(Message) line: 2033  
    ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 123 
    ActivityThread.main(String[]) line: 4627    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 521  
    ZygoteInit$MethodAndArgsCaller.run() line: 868  
    ZygoteInit.main(String[]) line: 626 
    NativeStart.main(String[]) line: not available [native method]  

This is my first post on stackoverflow, please let me know if there is any more information I may provide.

Thanks

Ant4res
  • 1,217
  • 1
  • 18
  • 36
John
  • 513
  • 1
  • 6
  • 11
  • 1
    Could you post the NullPointerException stacktrace ? – Norman Maurer Apr 23 '12 at 05:55
  • Please post the stacktrace of the error as well as the code lines where the error occurs. If you are using Eclipse you can find the stacktrace in the logcat window, otherwise check [this post on how to get the log](http://stackoverflow.com/q/2882253/741249) – THelper Apr 23 '12 at 12:02

1 Answers1

1

Thanks for pointing out the logcat window (I'm new to Eclipse). It showed another error: java.net.SocketException: Bad address family

After doing some research I found this: http://code.google.com/p/android/issues/detail?id=9431

The fix is to disable IPv6 when using the Emulator:

java.lang.System.setProperty("java.net.preferIPv6Addresses", "false");
John
  • 513
  • 1
  • 6
  • 11