2017-02-24 54 views
0

我想通過傳遞URL中的幾個值來調用API - 這在iOS上正常工作,但在Android上休息。React Native - 值'3130049174'不適合32位有符號int

例如api/v1/betslip/6/113672/669203/149/3130049174?product_id=5

3130049174導致錯誤的值:

enter image description here

錯誤是從54行引發https://github.com/mhallcouk/stopwatch/blob/master/node_modules/react-native/ReactAndroid/src/main/jni/xreact/jni/ReadableNativeMap.cpp

所以未能在integer != javaint

以下是完整的代碼:

getBetslipApi(settingsObj, 113672, 669203, 149, 3130049174) 



export function getBetslipApi(settings, eventID, marketID, rsID, partnerID) { 
//THE RSID IS THE VALUE CAUSING THE ERROR - 3130049174 

const url = settings.api+"v1/betslip/"+settings.sport_id+"/"+eventID+"/"+marketID+"/"+partnerID+"/"+rsID+"?product_id="+settings.product_id; 


return (dispatch) => { 
    dispatch(getBetslip()); 
    axios.get(url, { 
     headers: {'Cache-Control': 'max-age='+settings.api_cache_time}, 
     timeout: settings.api_timeout 
    }) 
     //THIS DOES NOT TRIGGER 
     .then((data) => { 
      console.log(data) 
      if(data.success) { 
       const url = data.data.betslip 
       Linking.canOpenURL(url).then(supported => { 
        if (!supported) { 
         console.log('Error opening external URL: ' + url); 
         return Linking.openURL(url); 
        } else { 
         return Linking.openURL(url); 
        } 
       }).catch(err => console.error('An error occurred', err)); 
       dispatch(getBetslipSuccess(data.data)) 
      }else { 
       apiError(data, url); 
       dispatch(getBetslipFailure(data)); 
      } 
     }) 
     .catch(function (error) { 
      console.log(error) 
      apiError(error, url); 
      dispatch(getBetslipFailure(error)); 
     }); 
} 

}

回答

1

int是一個32位有符號整數,這意味着它具有的2^-31最小值和的2^31-1

3130049174的最大值是這就是爲什麼它導致此問題的範圍之外的數。您可以使用doubleInteger包裝類來避免此問題。

相關問題