java.net.socketexception: socket failed: eacces (permission denied)

I am a Long time Trying  java.net.socketexception: socket failed: eacces (permission denied) solving. I tried looking into it the issue and was wondering if it is caused by the espresso-server app not having any permission declared in the AndroidManifest. ie.

<uses-configuration android:name=”android.permission.INTERNET”/>
<uses-permission android:name=”android.permission.ACCESS_WIFI_STATE” />
<uses-permission android:name=”android.permission.CHANGE_WIFI_STATE” />
<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” />
<uses-permission android:name=”android.permission.CHANGE_NETWORK_STATE” />

java.net.socketexception: socket failed: eacces (permission denied) Solve

<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=”.SecondActivity”></activity>
<activity android:name=”.MainActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>
MainActivity.java

public class MainActivity extends AppCompatActivity {

private EditText username;
private EditText password;
private Button login;

Connection con;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

username = (EditText)findViewById(R.id.username);
password = (EditText)findViewById(R.id.password);
login = (Button)findViewById(R.id.login);

login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new MainActivity.checkLogin().execute(“”);
}
});
}

private class checkLogin extends AsyncTask<String, String, String>{

String str = null;
Boolean isSuccess = false;

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

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
}

@Override
protected String doInBackground(String… strings) {
con = connectionClass(ConnectionClass.user.toString(),ConnectionClass.password.toString(),ConnectionClass.database.toString(),ConnectionClass.server.toString());
if(con == null){
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this,”Check Internet Connection”,Toast.LENGTH_LONG).show();
}
});
str = “On Internet Connection”;
}
else {
try {
String sql = “SELECT * FROM users WHERE username = ‘” + username.getText() + “‘ AND password = ‘” + password.getText() + “‘ “;
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);

if (rs.next()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, “Login Success”, Toast.LENGTH_LONG).show();
}
});
str = “Success”;

Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
finish();
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, “Check email or password”, Toast.LENGTH_LONG).show();
}
});

username.setText(“”);
password.setText(“”);
}
} catch (Exception e) {
isSuccess = false;
Log.e(“SQL Error : “, e.getMessage());
}
}
return str;
}
}

@SuppressLint(“NewApi”)
public Connection connectionClass(String user, String password, String database, String server){
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection connection = null;
String connectionURL = null;
try{
Class.forName(“com.mysql.jdbc.Driver”);
connectionURL = “jdbc:mysql://localhost/biddingapp://” + server+”/” + database + “;user=” + user + “;password=” + password + “;”;
connection = DriverManager.getConnection(connectionURL);
}catch (Exception e){
Log.e(“SQL Connection Error : “, e.getMessage());
}

return connection;
}
}

Author Details

admin photo

sobuj033@gmail.com

Sobuj Ali

Founder & CEO

Sobuj Ali is Founder & CEO at Apkpm.com. I have a good knowledge of Marketing. So I provide all Technology information on their website.

Leave a Reply

Your email address will not be published.

Your Rating: