publicclassMainActivity extends AppCompatActivity{privateEditTextETLogin,ETPass;privateButtonLogiButton;privateProgressBar progressBar;privatestaticString URL_S ="http://192.168.1.13/P/log.php";@Overrideprotectedvoid onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);ETLogin=(EditText)findViewById(R.id.TextLogin);ETPass=(EditText)findViewById(R.id.TextPass);LogiButton=(Button) findViewById(R.id.LoginBut);LogiButton.setOnClickListener(newView.OnClickListener(){@Overridepublicvoid onClick(View v){String memail =ETLogin.getText().toString().trim();String mpass =ETPass.getText().toString().trim();if(!memail.isEmpty()&&!mpass.isEmpty()){Login(memail , mpass);}//end ifelse{ETLogin.setError("Enter Name");ETPass.setError("Enter Pass");}//endelse}});}//endoncreateprivatevoidLogin(final String email, final String password){StringRequest stringRequest =newStringRequest(Request.Method.POST,URL_S,newResponse.Listener<String>(){@Overridepublicvoid onResponse(String response){try{JSONObject jsonObject =newJSONObject(response);String success = jsonObject.getString("success");JSONArray jsonArray = jsonObject.getJSONArray("login");if(success.equals("1")){for(int i =0;i<jsonArray.length();i++){JSONObjectObject=jsonArray.getJSONObject(i);String name =Object.getString("name").trim();String email =Object.getString("email").trim();Toast.makeText(MainActivity.this,"Success login"+name
+"\n"+email ,Toast.LENGTH_SHORT).show();}}}//end trycatch(JSONException e){
e.printStackTrace();Toast.makeText(MainActivity.this,"CachError\n"+
e.toString(),Toast.LENGTH_SHORT).show();}//end catch}//end onrespnse},//end listenernewResponse.ErrorListener(){@Overridepublicvoid onErrorResponse(VolleyError error){if(error instanceof TimeoutError|| error instanceof NoConnectionError){//This indicates that the reuest has either time out or there is no connectionToast.makeText(MainActivity.this,"1 \n"+
error.toString(),Toast.LENGTH_SHORT).show();}elseif(error instanceof AuthFailureError){Toast.makeText(MainActivity.this,"2 \n"+
error.toString(),Toast.LENGTH_SHORT).show();//Error indicating that there was an Authentication Failure while performing the request}elseif(error instanceof ServerError){Toast.makeText(MainActivity.this,"3 \n"+
error.toString(),Toast.LENGTH_SHORT).show();//Indicates that the server responded with a error response}elseif(error instanceof NetworkError){Toast.makeText(MainActivity.this,"4 \n"+
error.toString(),Toast.LENGTH_SHORT).show();//Indicates that there was network error while performing the request}elseif(error instanceof ParseError){Toast.makeText(MainActivity.this,"5 \n"+
error.toString(),Toast.LENGTH_SHORT).show();// Indicates that the server response could not be parsed}}//end onerrorrespnse})//errorlistener{@OverrideprotectedMap<String,String> getParams() throws AuthFailureError{Map<String,String>params =newHashMap<>();
params.put("email", email);
params.put("password", password);return params;}//map};RequestQueue requestQueue =Volley.newRequestQueue(MainActivity.this);
requestQueue.add(stringRequest);}}
السؤال
ميساء هاني
السلام عليكم ورحمة الله
ممكن مساعده في حل مشكلة com.android.volley.ServerError
حاولت بشتى الطرق لكن ماتوصلت للحل "(
اعمل ع login استخدمت سيرفير xampp
php login :
وهذا الكود java :
طبعا اضفت
الداتا بيس مع القيم اللي اضفتهم :
جزاكم الله خيير
2 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.