W / System.err:引起:libcore.io.ErrnoException:套接字失败:EACCES(权限被拒绝)

时间:2018-02-17 13:58:47

标签: android-manifest android-studio-3.0

![在这个项目中我一直得到libcore.io.ErrnoException:套接字失败:EACCES(权限被拒绝),我已经检查了所有与此问题相关的答案,对我没什么用,我添加的所有权限仍然相同。 ... 这是我的清单文件] [1]] [1]

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.progga.justcake">
<uses-permission android:name="android.permisson.INTERNET"></uses-permission>

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

<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.READ_PROFILE"></uses-permission>
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".Welcome">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Main2Activity"
        android:label="@string/title_activity_main2"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity android:name=".Main3Activity" />
    <activity android:name=".Register" />
    <activity android:name=".Login"></activity>
</application>

这是我的logcat异常
    02-17 13:24:49.540 1752-1768/com.example.progga.justcake W/System.err:        Caused by: libcore.io.ErrnoException: socket failed: EACCES (Permission denied)
    02-17 13:24:49.540 1752-1768/com.example.progga.justcake W/System.err:     at libcore.io.Posix.socket(Native Method)
    02-17 13:24:49.540 1752-1768/com.example.progga.justcake W/System.err:     at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:181)
    02-17 13:24:49.540 1752-1768/com.example.progga.justcake W/System.err:     at libcore.io.IoBridge.socket(IoBridge.java:568)
    02-17 13:24:49.540 1752-1768/com.example.progga.justcake W/System.err:  ... 23 more
    02-17 13:24:49.568 1752-1752/com.example.progga.justcake W/EGL_genymotion: eglSurfaceAttrib not implemented
这是我的背景代码..............
package com.example.progga.justcake;


public class BackgroundRegestration extends AsyncTask<String,Void,String> {
Context ctx;
BackgroundRegestration(Context ctx)
{
   this.ctx=ctx;
    Toast.makeText(ctx,"error3",Toast.LENGTH_LONG).show();
}

@Override
protected void onPreExecute() {
    super.onPreExecute();
}
@Override
protected String doInBackground(String...params) {

    Log.d("Asynctask", ""+params);
    Looper.prepare();
    String reg_url= "http://10.0.0.2/cakeshop/registration.php";
    String login_url= "http://10.0.0.2/cakeshop/Login.php";
    String method=params[0];
    Toast.makeText(ctx,"error4",Toast.LENGTH_LONG).show();
    if(method.equals("Register"))
    {
      String user_name=params[1];
        String email=params[2];
        String password=params[3];
        String address=params[4];
        String contact=params[5];
        try {
            URL url=new URL(reg_url);
          HttpURLConnection httpURLConnection= (HttpURLConnection)url.openConnection();
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setRequestMethod("POST");
            Toast.makeText(ctx,"error5",Toast.LENGTH_LONG).show();
            //httpURLConnection.setDoInput(true);
           OutputStream outputStream=httpURLConnection.getOutputStream();
           BufferedWriter bufferedWriter=new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
            String data= URLEncoder.encode("user_name","UTF-8")+"="+URLEncoder.encode(user_name,"UTF-8")+"&"
                    +URLEncoder.encode("email","UTF-8")+"="+URLEncoder.encode(email,"UTF-8")+"&"
                    +URLEncoder.encode("password","UTF-8")+"="+URLEncoder.encode(password,"UTF-8")+"&"
                    +URLEncoder.encode("address","UTF-8")+"="+URLEncoder.encode(address,"UTF-8")+"&"
                    +URLEncoder.encode("contact","UTF-8")+"="+URLEncoder.encode(contact,"UTF-8");
                    bufferedWriter.write(data);
                    bufferedWriter.flush();
                    bufferedWriter.close();
                    outputStream.close();
            Toast.makeText(ctx,"error6",Toast.LENGTH_LONG).show();
            InputStream inputStream=httpURLConnection.getInputStream();
           // BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
          //  String result="";
          //  String line="";
            //bufferedReader.close();
            inputStream.close();
           // httpURLConnection.disconnect();
            Toast.makeText(ctx,"error6",Toast.LENGTH_LONG).show();
            return "Registration success.......";
        } catch (MalformedURLException e) {
            e.printStackTrace();
            Toast.makeText(ctx,"error",Toast.LENGTH_LONG).show();

        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(ctx,"error23",Toast.LENGTH_LONG).show();
        }
    }
    Looper.loop();
    Looper.myLooper().quit();
    return null;
}

@Override
protected void onProgressUpdate(Void... values) {

    super.onProgressUpdate(values);
}

@Override
protected void onPostExecute(String result) {
    result="success";
    Toast.makeText(ctx,result,Toast.LENGTH_LONG).show();
}

}

1 个答案:

答案 0 :(得分:0)

在后台代码中,IOexception和MalfxceormedURLException应该只替换为Exception,这将在logcat中显示正确的异常,这不是互联网权限问题.............