当前位置: 首页 > 知识库问答 >
问题:

原因:libcore.io.errnoException:套接字失败:EACCES(拒绝权限)

施飞昂
2023-03-14

我找了几个地方,试了很多东西,但我不明白这里出了什么问题:(请帮帮我。

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.ramim.loginattempt.app.*;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends Activity implements View.OnClickListener {
    TextView tv;
    EditText inid,inpass;
    Button blog;
    static String result;
    Intent logged;
   final String key_uname="myusername",key_pass="mypassword";
    RequestQueue reQue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        inid=(EditText)findViewById(R.id.iuserid);
        inpass=(EditText)findViewById(R.id.ipass);
        blog=(Button)findViewById(R.id.button);
        logged= new Intent(this,logsuccess.class);
        reQue= Volley.newRequestQueue(this);
        blog.setOnClickListener(this);

    }

    private void checkLogin(final String username, final String pass) {
        tv= (TextView)findViewById(R.id.output);
        StringRequest myreq= new StringRequest(Request.Method.POST, config.Loginfile, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
            }
        },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(getApplicationContext(),error.toString(),Toast.LENGTH_SHORT).show();
                    }
                }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String,String> params= new HashMap<String , String>();
                params.put(key_uname,username);
                params.put(key_pass,pass);
                return params;
            }
        };

            reQue.add(myreq);

        JsonObjectRequest jreq= new JsonObjectRequest(Request.Method.GET, config.Loginfile, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try{
                    result=response.getString("value");
                   tv.setText(result);

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        },new Response.ErrorListener(){
            public void onErrorResponse(VolleyError error){
                error.printStackTrace();
            }
        });
       reQue.add(jreq);
    }
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.ramim.loginattempt" >

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

    <application
        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>
        <activity android:name=".logsuccess" >
        </activity>
    </application>

</manifest>

共有1个答案

宰父俊民
2023-03-14

您得internet访问权限在清单中不正确.这一行:

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

应该改为:

<uses-permission android:name="android.permission.INTERNET" />
 类似资料: