我已经搜索了几个地方,尝试了很多事情,但我不明白这里出了什么问题:(请帮帮我。

这是我的代码:

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>


日志文件:


02-14 01:22:20.182 1545-1545 / com.example.ramim.loginattempt
W / System.err:com.android.volley.NoConnectionError:
java.net.SocketException:套接字失败:EACCES(权限被拒绝)
02-14 01:22:20.182 1545-1545 / com.example.ramim.loginattempt
W / System.err:位于
com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:133)
02-14 01:22:20.182 1545-1545 / com.example.ramim.loginattempt
W / System.err:位于
com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:105)
02-14 01:22:20.182 1545-1545 / com.example.ramim.loginattempt
W / System.err:原因:java.net.SocketException:套接字失败:
EACCES(权限被拒绝)02-14 01:22:20.182
1545-1545 / com.example.ramim.login尝试W / System.err:在
libcore.io.IoBridge.socket(IoBridge.java:576)02-14 01:22:20.182
1545-1545 / com.example.ramim.login尝试W / System.err:在
java.net.PlainSocketImpl.create(PlainSocketImpl.java:201)02-14
01:22:20.182 1545-1545 / com.example.ramim.login尝试W / System.err:
在java.net.Socket.checkOpenAndCreate(Socket.java:664)02-14
01:22:20.182 1545-1545 / com.example.ramim.login尝试W / System.err:
在java.net.Socket.connect(Socket.java:808)02-14 01:22:20.182
1545-1545 / com.example.ramim.login尝试W / System.err:在
com.android.okhttp.internal.Platform.connectSocket(Platform.java:131)
02-14 01:22:20.182 1545-1545 / com.example.ramim.loginattempt
W / System.err:位于
com.android.okhttp.Connection.connect(Connection.java:101)02-14
01:22:20.182 1545-1545 / com.example.ramim.login尝试W / System.err:

com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
02-14 01:22:20.182 1545-1545 / com.example.ramim.loginattempt
W / System.err:位于
com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
02-14 01:22:20.182 1545-1545 / com.example.ramim.loginattempt
W / System.err:位于
com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
02-14 01:22:20.182 1545-1545 / com.example.ramim.loginattempt
W / System.err:位于
com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
02-14 01:22:20.182 1545-1545 / com.example.ramim.loginattempt
W / System.err:位于
com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)
02-14 01:22:20.182 1545-1545 / com.example.ramim.loginattempt
W / System.err:位于
com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503)
02-14 01:22:20.182 1545-1545 / com.example.ramim.loginattempt
W / System.err:位于
com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:109)
02-14 01:22:20.182 1545-1545 / com.example.ramim.loginattempt
W / System.err:位于
com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:93)
02-14 01:22:20.182 1545-1545 / com.example.ramim.loginattempt
W / System.err:...另外1个02-14 01:22:20.186
1545-1545 / com.example.ramim.login尝试W / System.err:原因:
libcore.io.ErrnoException:套接字失败:EACCES(权限被拒绝)
02-14 01:22:20.186 1545-1545 / com.example.ramim.loginattempt
W / System.err:位于libcore.io.Posix.socket(本机方法)02-14
01:22:20.186 1545-1545 / com.example.ramim.login尝试W / System.err:
在libcore.io.BlockGuardOs.socket(BlockGuardOs.java:181)02-14
01:22:20.186 1545-1545 / com.example.ramim.login尝试W / System.err:
在libcore.io.IoBridge.socket(IoBridge.java:561)02-14 01:22:20.186
1545-1545 / com.example.ramim.login尝试W / System.err:...还有14个


请帮帮我

最佳答案

您的清单中的互联网访问权限不正确。这行:

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


应该改为:

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

09-05 13:08