Android java.net.SocketException:套接字失败

时间:2016-01-13 08:24:12

标签: java android sockets

我在我的应用程序中使用xsocket,但是当我初始化应用程序时,我收到了这些错误消息

01-13 15:34:54.760 8457-8457/com.example.administrator.socket W/System.err: java.net.SocketException: socket failed: EACCES (Permission denied)
01-13 15:34:54.762 8457-8457/com.example.administrator.socket W/System.err:     at libcore.io.IoBridge.socket(IoBridge.java:576)
01-13 15:34:54.762 8457-8457/com.example.administrator.socket W/System.err:     at java.nio.SocketChannelImpl.<init>(SocketChannelImpl.java:102)
01-13 15:34:54.762 8457-8457/com.example.administrator.socket W/System.err:     at java.nio.SocketChannelImpl.<init>(SocketChannelImpl.java:93)
01-13 15:34:54.763 8457-8457/com.example.administrator.socket W/System.err:     at java.nio.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:49)
01-13 15:34:54.763 8457-8457/com.example.administrator.socket W/System.err:     at java.nio.channels.SocketChannel.open(SocketChannel.java:81)
01-13 15:34:54.763 8457-8457/com.example.administrator.socket W/System.err:     at org.xsocket.connection.NonBlockingConnection.openSocket(NonBlockingConnection.java:2400)
01-13 15:34:54.764 8457-8457/com.example.administrator.socket W/System.err:     at org.xsocket.connection.NonBlockingConnection.<init>(NonBlockingConnection.java:724)
01-13 15:34:54.764 8457-8457/com.example.administrator.socket W/System.err:     at org.xsocket.connection.NonBlockingConnection.<init>(NonBlockingConnection.java:707)
01-13 15:34:54.764 8457-8457/com.example.administrator.socket W/System.err:     at org.xsocket.connection.NonBlockingConnection.<init>(NonBlockingConnection.java:450)
01-13 15:34:54.764 8457-8457/com.example.administrator.socket W/System.err:     at com.ticket.pos.sesssion.PosConnection.init(PosConnection.java:41)
01-13 15:34:54.765 8457-8457/com.example.administrator.socket W/System.err:     at com.example.administrator.socket.MyApp.initSocketClient(MyApp.java:54)
01-13 15:34:54.765 8457-8457/com.example.administrator.socket W/System.err:     at com.example.administrator.socket.MyApp.<init>(MyApp.java:40)
01-13 15:34:54.765 8457-8457/com.example.administrator.socket W/System.err:     at java.lang.Class.newInstanceImpl(Native Method)
01-13 15:34:54.765 8457-8457/com.example.administrator.socket W/System.err:     at java.lang.Class.newInstance(Class.java:1208)
01-13 15:34:54.765 8457-8457/com.example.administrator.socket W/System.err:     at android.app.Instrumentation.newApplication(Instrumentation.java:990)
01-13 15:34:54.766 8457-8457/com.example.administrator.socket W/System.err:     at android.app.Instrumentation.newApplication(Instrumentation.java:975)
01-13 15:34:54.766 8457-8457/com.example.administrator.socket W/System.err:     at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
01-13 15:34:54.766 8457-8457/com.example.administrator.socket W/System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4330)
01-13 15:34:54.766 8457-8457/com.example.administrator.socket W/System.err:     at android.app.ActivityThread.access$1500(ActivityThread.java:135)
01-13 15:34:54.766 8457-8457/com.example.administrator.socket W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-13 15:34:54.767 8457-8457/com.example.administrator.socket W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
01-13 15:34:54.767 8457-8457/com.example.administrator.socket W/System.err:     at android.os.Looper.loop(Looper.java:136)
01-13 15:34:54.767 8457-8457/com.example.administrator.socket W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5030)
01-13 15:34:54.767 8457-8457/com.example.administrator.socket W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
01-13 15:34:54.767 8457-8457/com.example.administrator.socket W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
01-13 15:34:54.768 8457-8457/com.example.administrator.socket W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
01-13 15:34:54.768 8457-8457/com.example.administrator.socket W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
01-13 15:34:54.768 8457-8457/com.example.administrator.socket W/System.err:     at dalvik.system.NativeStart.main(Native Method)
01-13 15:34:54.769 8457-8457/com.example.administrator.socket W/System.err: Caused by: libcore.io.ErrnoException: socket failed: EACCES (Permission denied)
01-13 15:34:54.770 8457-8457/com.example.administrator.socket W/System.err:     at libcore.io.Posix.socket(Native Method)
01-13 15:34:54.770 8457-8457/com.example.administrator.socket W/System.err:     at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:181)
01-13 15:34:54.770 8457-8457/com.example.administrator.socket W/System.err:     at libcore.io.IoBridge.socket(IoBridge.java:561)
01-13 15:34:54.770 8457-8457/com.example.administrator.socket W/System.err:     ... 27 more

但我已经选择了manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:sharedUserId="android.uid.system"
    package="com.example.administrator.socket" >
    <permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:name=".MyApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我认为这不是导致的许可。 我怎么能解决这个问题呢,非常感谢

2 个答案:

答案 0 :(得分:1)

将“uses-”添加到INTERNET权限。就像你和其他人一样! -

答案 1 :(得分:1)

您的问题与权限有关。替换清单

中的以下行
<permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.INTERNET" />

你的例外将会消失