When I try to run my code it gives me that error which is in question first, it gives me an error of cleartext HTTP is not permitted then I try to fix it by adding this line to manifest file android:usesCleartextTraffic="true" after this, its give me a timeout error I also try these to fix it click here but it's not working here is my code
private void Login() {
ID=loginID.getText().toString();
password=loginPassword.getText().toString();
if (ID.isEmpty()){
loginID.setError("This field cannot be empty");
loginPassword.setText("");
}else if (password.isEmpty()){
loginPassword.setError("This field cannot be empty");
}else {
StringRequest stringRequest=new StringRequest(Request.Method.POST, login_url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
responseServer.setText("Successfull");
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String e=error.toString();
responseServer.setText(e);
error.printStackTrace();
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params=new HashMap<String, String>();
params.put("user_id",ID);
params.put("user_password",password);
return params;
}
};
MySingleton.getInstance(getApplicationContext()).addToRequestque(stringRequest);
//AppController.getInstance().addToRequestQueue(stringRequest);
}
}
here is MySingleton class package com.example.schoolmanagementsystem;
import android.content.Context;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
public class MySingleton {
private static MySingleton mInstance;
private static RequestQueue requestQueue;
private static Context context;
public MySingleton(Context mCx) {
context=mCx;
requestQueue=getRequestQueue();
}
public RequestQueue getRequestQueue() {
if(requestQueue==null){
requestQueue= Volley.newRequestQueue(context.getApplicationContext());
}
return requestQueue;
}
public static synchronized MySingleton getInstance(Context context){
if (mInstance==null){
mInstance=new MySingleton(context);
}
return mInstance;
}
public <T>void addToRequestque(Request<T> request){
requestQueue.add(request);
}
}
I am using android 3.3.2 and android pie to run this