Mohaimanul Chowdhury Mohaimanul Chowdhury - 6 months ago 533
Android Question

Caused by: libcore.io.ErrnoException: socket failed: EACCES (Permission denied)

I've searched a few places, tried many things, yet i don't understand what is wrong here :( please help me out.

Here is my code:

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);
}


the manifest:

<?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>


logfile:


02-14 01:22:20.182 1545-1545/com.example.ramim.loginattempt
W/System.err: com.android.volley.NoConnectionError:
java.net.SocketException: socket failed: EACCES (Permission denied)
02-14 01:22:20.182 1545-1545/com.example.ramim.loginattempt
W/System.err: at
com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:133)
02-14 01:22:20.182 1545-1545/com.example.ramim.loginattempt
W/System.err: at
com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:105)
02-14 01:22:20.182 1545-1545/com.example.ramim.loginattempt
W/System.err: Caused by: java.net.SocketException: socket failed:
EACCES (Permission denied) 02-14 01:22:20.182
1545-1545/com.example.ramim.loginattempt W/System.err: at
libcore.io.IoBridge.socket(IoBridge.java:576) 02-14 01:22:20.182
1545-1545/com.example.ramim.loginattempt W/System.err: at
java.net.PlainSocketImpl.create(PlainSocketImpl.java:201) 02-14
01:22:20.182 1545-1545/com.example.ramim.loginattempt W/System.err:

at java.net.Socket.checkOpenAndCreate(Socket.java:664) 02-14
01:22:20.182 1545-1545/com.example.ramim.loginattempt W/System.err:

at java.net.Socket.connect(Socket.java:808) 02-14 01:22:20.182
1545-1545/com.example.ramim.loginattempt W/System.err: at
com.android.okhttp.internal.Platform.connectSocket(Platform.java:131)
02-14 01:22:20.182 1545-1545/com.example.ramim.loginattempt
W/System.err: at
com.android.okhttp.Connection.connect(Connection.java:101) 02-14
01:22:20.182 1545-1545/com.example.ramim.loginattempt W/System.err:

at
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: at
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: at
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: at
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: at
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: at
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: at
com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:109)
02-14 01:22:20.182 1545-1545/com.example.ramim.loginattempt
W/System.err: at
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 more 02-14 01:22:20.186
1545-1545/com.example.ramim.loginattempt W/System.err: Caused by:
libcore.io.ErrnoException: socket failed: EACCES (Permission denied)

02-14 01:22:20.186 1545-1545/com.example.ramim.loginattempt
W/System.err: at libcore.io.Posix.socket(Native Method) 02-14
01:22:20.186 1545-1545/com.example.ramim.loginattempt W/System.err:

at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:181) 02-14
01:22:20.186 1545-1545/com.example.ramim.loginattempt W/System.err:

at libcore.io.IoBridge.socket(IoBridge.java:561) 02-14 01:22:20.186
1545-1545/com.example.ramim.loginattempt W/System.err: ... 14 more


please help me out

Answer

in my case adding

compile 'com.android.volley:volley:1.0.0' 

to my dependency worked rather than using that mcix thing