question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] Error "Value for value cannot be cast from String to Double" on send message

See original GitHub issue

Hello there, I developed an app that works fine on iOS and now I want to compile the Android version, but I came across a strange error (see the attachment).

screenshot_2019-01-28-15-49-31

I would like to understand if it is a problem I can solve simply by updating the version of react-native-gifted-chat or the react-native core.

Steps to Reproduce / Code Snippets

  • package.json
"dependencies": {
    "react": "16.6.3",
    "react-native": "0.57.8",
    ...
    "react-native-firebase": "5.2.1",
    "react-native-gifted-chat": "0.5.0",
    ...
}
  • Chat.js
import React, { Component } from 'react';
import { GiftedChat, Send, Bubble } from 'react-native-gifted-chat';
...

export default class ChatScreen extends Component {
  state = {
    messages: []
  }
  chatRoomRef = null;
  unsubscribe = null;
  _chatRoomListener = (querySnapshot) => {
    const messages = querySnapshot.docs.map(doc => 
      createGiftedChatItem(doc.id, doc.data()) // --> a custom function to create message object
    );
    this.setState(prevState => ({
      ...prevState,
      messages
    }));
  }
  componentDidMount = () => {
    const { navigation } = this.props;
    // My custom Firebase methods
    this.chatRoomRef = database.chatRoomMessagesByPath(REF_TO_FIRESTORE_PATH);
    this.unsubscribe = this.chatRoomRef.orderBy('createdAt', 'desc').onSnapshot(this._chatRoomListener);
  }
  componentWillUnmount = () => {
    if (this.unsubscribe) {
      this.unsubscribe();
    }
  }
  sendMessageHandler = (messages = []) => {
    messages.forEach(message => {
      let lastMessage = createChatMessageItem(message); // --> a custom function to create message object
      this.chatRoomRef.add(lastMessage).then(() => 
        database.chatRoomByPath(path).update({lastMessage})
      ).then(() => {
        // --> other omitted methods here
      });
    });
  }
  render() {
    const { messages } = this.state;
    return (
      <GiftedChat
        user={{_id: XXXXXXXX}}
        locale="en"
        dateFormat="LL"
        timeFormat="LT"
        messages={messages}
        renderAvatar={null}
        renderSend={props => (
          <Send {...props} containerStyle={styles.sendBtn}>
            <MaterialIcon name="send" size={24} color={THEME_PRIMARY_COLOR} />
          </Send>
        )}
        renderBubble={props => (
          <Bubble 
            {...props} 
            wrapperStyle={{
              right: {backgroundColor: THEME_OWNER_CHAT_BUBBLE, padding: 12, borderRadius: 8}, 
              left: {backgroundColor: THEME_GUEST_CHAT_BUBBLE, padding: 12, borderRadius: 8}
            }}
            textStyle={{
              right: {color: THEME_GRAY_COLOR},
              left: {color: THEME_GRAY_COLOR}
            }}
            textProps={{
              style: {color: THEME_TEXT_COLOR}
            }}
          />
        )}
        onSend={message => this.sendMessageHandler(message)}
      />
    )
  }
}

Expected Results

I don’t understand why on iOS everything works fine, while on Android the chat message is correctly saved on Firestore, but this error is shown.

Additional Information

  • React version: 16.6.3
  • React Native version: 0.57.8
  • react-native-gifted-chat version: 0.5.0
  • Platform(s): Android

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
rajeevrocker7commented, Jul 30, 2019

For ‘TextInput’ in style try after removing backgroundColor, color, if passed.

textInputStyle: { … backgroundColor: ‘#FFFFF’, // remove this color: ‘black’ . //remove this }

1reaction
paolospagcommented, Feb 11, 2019

No, I don’t make any transformation and I can’t really explain why it happens. I’m quite confused… I will try to update from 0.5.0 to 0.7.2 and I will let you know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-native error : value for date cannot be cast from string to ...
now when I click on the datepicker, it gives an error saying: value for date cannot be cast from string to double ....
Read more >
value for message cannot be cast from readablenativearray to ...
I keep getting this error on my react native application. Fatal Exception: java.lang.ClassCastException: Value for message cannot be cast from ReadableNativeMap ...
Read more >
Java Convert double to String - javatpoint
It is generally used if we have to display double value in textfield for GUI application because everything is displayed as a string...
Read more >
cast function | Databricks on AWS
Databricks raises an error if the cast isn't supported or if any of the keys or values can't be cast. Use try_cast to...
Read more >
Convert String to Double in Java - GeeksforGeeks
double str1 = Double.valueOf(str);. Example: Java. Java ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found