Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix java.lang.Double cannot be cast to java.lang.String in React Native

Tags:

react-native

I have problem regarding on my AsyncStorage.getItem. I have module which is the login, where I need to set the item inside the storage, after I get the result there is an yellow message below that I have Error: java.lang.Double cannot be cast to java.lang.String I didn't know where the error came.

Error

I will show you guys, my function to set the item in the storage.

     if(response.status == '200')
     {
          AsyncStorage.setItem('authorization_code',access_token);
          AsyncStorage.setItem('authorization_expiration',expires_in);
          AsyncStorage.setItem('authorization_type',token_type);

          //let token = AsyncStorage.getItem(JSON.stringify("authorization_code"));
           AsyncStorage.getItem('authorization_code', (err, result) => {
            alert(result);
          });

     }
like image 612
DevGe Avatar asked May 23 '19 16:05

DevGe


1 Answers

Use toString() to force type in js side. I suppose that is expires_in the floating point number here, so:

          AsyncStorage.setItem('authorization_code',access_token);
          AsyncStorage.setItem('authorization_expiration',expires_in.toString());
          AsyncStorage.setItem('authorization_type',token_type);
like image 83
isalgueiro Avatar answered Nov 02 '22 23:11

isalgueiro