2016-06-30 45 views
1

在下面的代碼中出現此錯誤的原因是什麼?org.json.JSONException:名稱沒有值

loginButton.setOnClickListener(new View.OnClickListener() 
     { 
      @Override 
      public void onClick (View v){ 
       final String e_mail = e_mailEditText.getText().toString(); 
       final String password = passwordEditText.getText().toString(); 

       // Response received from the server 
       Response.Listener<String> responseListener = new Response.Listener<String>() { 
        @Override 
        public void onResponse(String response) { 
         try { 
          JSONObject jsonResponse = new JSONObject(response); 
          boolean success = jsonResponse.getBoolean("success"); 

          if (success) { 
           String name = jsonResponse.getString("name"); 
           // int age = jsonResponse.getInt("age"); 

           Intent intent = new Intent(login.this, Welcome.class); 
           intent.putExtra("name", name); 
           // intent.putExtra("age", age); 
           intent.putExtra("e_mail", e_mail); 
           login.this.startActivity(intent); 
          } else { 
           AlertDialog.Builder builder = new AlertDialog.Builder(login.this); 
           builder.setMessage("Login Failed") 
             .setNegativeButton("Retry", null) 
             .create() 
             .show(); 
          } 

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

       LoginRequest loginRequest = new LoginRequest(e_mail, password, responseListener); 
       RequestQueue queue = Volley.newRequestQueue(login.this); 
       queue.add(loginRequest); 
      } 
     }); 
+0

感謝丹羅氏它的工作感謝上帝 –

+0

我該如何修復它我有它註釋掉 –

回答

0

不能肯定地說,不知道的情況下(或異常的行號),但我的錢將是對呼叫:

jsonResponse.getString("name") 

最有可能的,從收到的JSON該服務器不包含名稱爲name的任何名稱/值對。

相關問題