2016-01-11 33 views
-1

這是我的代碼,用於請求由sms接收的sendCode。當號碼輸入並提交時,它會崩潰,我仍然通過短信收到代碼。java.lang.ClassCastException:java.util.HashMap不能轉換爲com.parse.ParseObject

ParseCloud.callFunctionInBackground("sendCode", params, new FunctionCallback<JSONObject>() { 
        public void done(JSONObject response, ParseException e) { 
         progressBar.setVisibility(View.GONE); 
         if (e == null) { 
          Log.d("Cloud Response", "There were no exceptions! " + response.toString()); 
          codeUI(); 
         } else { 
          Log.d("Cloud Response", "Exception: " + response.toString() + e); 
          Toast.makeText(getApplicationContext(), 
            "Something went wrong. Please try again." + e, 
            Toast.LENGTH_LONG).show(); 
          phoneNumberUI(); 
         } 
        } 
       }); 

這是在解析雲

if (!phoneNumber || (phoneNumber.length != 10 && phoneNumber.length != 11)) return res.error('Invalid Parameters'); 
    Parse.Cloud.useMasterKey(); 
    var query = new Parse.Query(Parse.User); 
    query.equalTo('username', phoneNumber + ""); 
    query.first().then(function(result) { 
     var min = 1000; var max = 9999; 
     var num = Math.floor(Math.random() * (max - min + 1)) + min; 

     if (result) { 
      result.setPassword(secretPasswordToken + num); 
      result.set("language", language); 
      result.save().then(function() { 
       return sendCodeSms(phoneNumber, num, language); 
      }).then(function() { 
       res.success({}); 
      }, function(err) { 
       res.error(err); 
      }); 
+0

通過短信請求代碼中的應用程序崩潰。應用程序崩潰後,我通過短信獲取代碼。 –

+0

請提供完整的堆棧跟蹤。我知道你在問題上發佈了它,但這不一定是異常的原因。所以有必要看到完整的logcat輸出。 – Opiatefuchs

回答

0

的ParseCloud函數返回基於您的JavaScript,所以你可以有你的代碼類似下面的HashMap的層次我的JSON文件。

ParseCloud.callFunctionInBackground("sendCode", params, new FunctionCallback<HashMap<String, Object>>() { 
    public void done(HashMap<String, Object> response, ParseException e) { 
     progressBar.setVisibility(View.GONE); 
     if (e == null) { 
      Log.d("Cloud Response", "There were no exceptions! " + response.toString()); 
      Log.d("Cloud Response", response.get("data").toString()); 
      codeUI(); 
     } else { 
      Log.d("Cloud Response", "Exception: " + response.toString() + e); 
      Toast.makeText(getApplicationContext(), "Something went wrong. Please try again." + e, Toast.LENGTH_LONG).show(); 
      phoneNumberUI(); 
     } 
    } 
}); 

然後,在JavaScript可以爲響應做...

response.success({ data: "yay" }); 
相關問題