Derrickjl
Derrickjl
采纳率0%
2017-03-14 15:22 阅读 2.6k

android中使用Netty当客户端时候出现以下错误连接不上

Caused by: io.netty.channel.ChannelException: Failed to open a socket.
at io.netty.channel.socket.nio.NioSocketChannel.newSocket(NioSocketChannel.java:63)
at io.netty.channel.socket.nio.NioSocketChannel.(NioSocketChannel.java:80)
at io.netty.channel.socket.nio.NioSocketChannel.(NioSocketChannel.java:73)
at java.lang.Class.newInstance(Native Method)
at io.netty.channel.ReflectiveChannelFactory.newChannel(ReflectiveChannelFactory.java:38)
at io.netty.bootstrap.AbstractBootstrap.initAndRegister(AbstractBootstrap.java:319) 
at io.netty.bootstrap.Bootstrap.doResolveAndConnect(Bootstrap.java:163) 
at io.netty.bootstrap.Bootstrap.connect(Bootstrap.java:119) 
at com.client.Client.connect(Client.java:43) 
at com.example.shx.serachnote.Main.onCreate(Main.java:43) 
at android.app.Activity.performCreate(Activity.java:6664) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
Caused by: java.net.SocketException: Permission denied
at sun.nio.ch.Net.socket0(Native Method)
at sun.nio.ch.Net.socket(Net.java:433)
at sun.nio.ch.Net.socket(Net.java:426)
at sun.nio.ch.SocketChannelImpl.(SocketChannelImpl.java:107)
at sun.nio.ch.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:60)
at io.netty.channel.socket.nio.NioSocketChannel.newSocket(NioSocketChannel.java:61)
at io.netty.channel.socket.nio.NioSocketChannel.(NioSocketChannel.java:80) 
at io.netty.channel.socket.nio.NioSocketChannel.(NioSocketChannel.java:73) 
at java.lang.Class.newInstance(Native Method) 
at io.netty.channel.ReflectiveChannelFactory.newChannel(ReflectiveChannelFactory.java:38) 
at io.netty.bootstrap.AbstractBootstrap.initAndRegister(AbstractBootstrap.java:319) 
at io.netty.bootstrap.Bootstrap.doResolveAndConnect(Bootstrap.java:163) 
at io.netty.bootstrap.Bootstrap.connect(Bootstrap.java:119) 
at com.client.Client.connect(Client.java:43) 
at com.example.shx.serachnote.Main.onCreate(Main.java:43) 
at android.app.Activity.performCreate(Activity.java:6664) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • Z_DingHao 鼎鼎浩 2017-03-16 11:42
     <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.INTERNET" />
    
    点赞 1 评论 复制链接分享
  • Z_DingHao 鼎鼎浩 2017-03-16 11:41

    打开socket错误,权限没有声明,在AndroidManifest.xml文件中加入权限



    当然 如果你是通过wifi连接socket的话记得开wifi的权限

    点赞 评论 复制链接分享

相关推荐