2017-05-06 3 views
0

Ich benutze Android Volley, um auf meine JSON-Daten von meinem Remote-MySQL-Datenbank zuzugreifen. Meistens bekommt es keine Daten, es geht immer in response.errorlistener Teil, aber irgendwann klappt es gut. Bitte sagen Sie mir, wie Sie am effektivsten auf Webdienste zugreifen können.Kann Json Daten nicht richtig

05-06 13:18:49.055 18409-18409/com.goworks.readyworks D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.2, mControlPoint1y = 0.65, mControlPoint2x = 0.28, mControlPoint2y = 0.97 05-06 13:18:49.055 18409-18409/com.goworks.readyworks D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.2, mControlPoint1y = 0.65, mControlPoint2x = 0.28, mControlPoint2y = 0.97 05-06 13:18:49.055 18409-18409/com.goworks.readyworks D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.2, mControlPoint1y = 0.65, mControlPoint2x = 0.28, mControlPoint2y = 0.97 05-06 13:18:49.055 18409-18409/com.goworks.readyworks D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.2, mControlPoint1y = 0.65, mControlPoint2x = 0.28, mControlPoint2y = 0.97 05-06 13:18:49.085 18409-18805/com.goworks.readyworks E/Volley: [569] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() at android.os.Handler.(Handler.java:200) at android.os.Handler.(Handler.java:114) at android.widget.Toast$TN.(Toast.java:342) at android.widget.Toast.(Toast.java:99) at android.widget.Toast.makeText(Toast.java:248) at com.goworks.readyworks.RegisterActivity$5.getParams(RegisterActivity.java:314) at com.android.volley.Request.getBody(Request.java:468) at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:253) at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:227) at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:107) at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:97) at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114) 05-06 13:18:49.235 18409-18409/com.goworks.readyworks E/Registration Error:: com.android.volley.VolleyError: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

if (isValidated()) { 

      pDialog = new ProgressDialog(RegisterActivity.this); 
      pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
      pDialog.setTitle("Making a member"); 
      pDialog.setMessage("Please Wait..."); 
      pDialog.setIndeterminate(true); 
      pDialog.setCancelable(true); 
      pDialog.show(); 

      userUsername = uname.getText().toString(); 
      userPassword = pass.getText().toString(); 
      emailAddress = email.getText().toString(); 
      userAddress = address.getText().toString(); 
      userContact = contact.getText().toString(); 

      StringRequest stringrequest = new StringRequest(Request.Method.POST, url + "registration.php", 
        new Response.Listener<String>() { 
         @Override 
         public void onResponse(String response) { 
          try { 

           JSONArray jsonArray = new JSONArray(response); 
           JSONObject jsonObject = jsonArray.getJSONObject(0); 
           String code = jsonObject.getString("code"); 
           String message = jsonObject.getString("message"); 

           if (code.equals("reg_success")) { 
            Toast.makeText(RegisterActivity.this, message, Toast.LENGTH_SHORT).show(); 
            pDialog.cancel(); 
            Intent intent = new Intent(RegisterActivity.this, LoginActivity.class); 
            startActivity(intent); 
            finish(); 

           } else if (code.equals("reg_failed")) { 
//         Snackbar.make(v, message, Snackbar.LENGTH_LONG).setAction("Action", null).show(); 
            pDialog.cancel(); 
            Toast.makeText(getApplicationContext(),"Not Registered",Toast.LENGTH_SHORT).show(); 

           } 


          } catch (JSONException e) { 
           e.printStackTrace(); 
          } 

         } 
        }, new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
          Toast.makeText(getApplicationContext(), "Something went wrong, Please try again", Toast.LENGTH_SHORT).show(); 
//     Snackbar.make(v, "Something went wrong, Please try again", Snackbar.LENGTH_LONG).setAction("Action", null).show(); 
        pDialog.cancel(); 
        Log.e("Registration Error:", String.valueOf(error)); 
       } 
      }) { 
       @Override 
       protected Map<String, String> getParams() throws AuthFailureError { 
        Map<String, String> params = new HashMap<String, String>(); 

        params.put("username", userUsername); 
        params.put("password", userPassword); 
        params.put("email", emailAddress); 
        params.put("contact", userContact); 
        params.put("address", userAddress); 
        params.put("location", finalCoords); 

        Toast.makeText(getApplicationContext(), "Data Delievered", Toast.LENGTH_SHORT).show(); 

        return params; 
       } 
      }; 

      RequestQueue requestQueue = Volley.newRequestQueue(RegisterActivity.this); 
      requestQueue.add(stringrequest); 
     } 
+1

Code darstellen und mit anderen teilen logcat –

+0

das Problem Ihrer Remote-MySQL-Datenbank ist. –

+0

es gibt nur Problem im Registrierungsteil. im Login-Teil und in anderen Dingen funktioniert es einwandfrei. –

Antwort

0

Prüfen Sie zuerst, was Fehler Code unten durch Zugabe in onErrorResponse(..){

if (error instanceof TimeoutError) { 
Toast.makeText(context,"TimeoutError",Toast.LENGTH_SHORT).show(); 
} else if (error instanceof NoConnectionError) { 
    Toast.makeText(context,"NoConnectionError",Toast.LENGTH_SHORT).show(); 
} else if (error instanceof AuthFailureError) { 
    Toast.makeText(context,"AuthFailureError",Toast.LENGTH_SHORT).show(); 
} else if (error instanceof ServerError) { 
    Toast.makeText(context,"ServerError",Toast.LENGTH_SHORT).show(); 
} else if (error instanceof NetworkError) { 
    Toast.makeText(context,"NetworkError",Toast.LENGTH_SHORT).show(); 
} else if (error instanceof ParseError) { 
    Toast.makeText(context,"ParseError",Toast.LENGTH_SHORT).show(); 
} 
+0

es zeigt nichts .... –

+0

was ist response string? –

+0

Versuchen Sie diese Zeile fälschlicherweise, was Sie bekommen? 'Toast.makeText (context, error.getMessage(), Toast.LENGTH_SHORT) .show();' –