Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: java.lang.Double cannot be cast to java.lang.String #7

Closed
saberprashant opened this issue Sep 26, 2018 · 8 comments
Closed

Error: java.lang.Double cannot be cast to java.lang.String #7

saberprashant opened this issue Sep 26, 2018 · 8 comments

Comments

@saberprashant
Copy link

saberprashant commented Sep 26, 2018

Hi there, @alwx @janherich @mandrigin @yenda

I am trying to use this package and I followed that little documentation, but I am getting this error on running the app on android device(Redmi Note 5). I don't know what is the exact problem, but I tried to search for it and did some trial and error, so I figured out that the code inside componentWillMount() is creating the problem.
Currently, my app code is:

import React, { Component } from 'react';
import { StyleSheet, View, Text } from 'react-native';
import httpBridge from 'react-native-http-bridge';

class App extends Component {
  componentWillMount() {
    // initalize the server (now accessible via localhost:1234)
    httpBridge.start(5561, (request) => {

        // you can use request.url, request.type and request.postData here
        if (request.type === "GET" && request.url.split("/")[1] === "users") {
          httpBridge.respond(200, "application/json", "{\"message\": \"OK\"}");
        } else {
          httpBridge.respond(400, "application/json", "{\"message\": \"Bad Request\"}");
        }

    });
  }

  componentWillUnmount() {
    httpBridge.stop();
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.instructions}>To get started</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'lightgrey',
  },
  welcome: {
    fontSize: 50,
    textAlign: 'center',
    margin: 20,
    color: 'red'
  },
  instructions: {
    textAlign: 'right',
    color: '#333333',
    marginBottom: 5,
  },
});

export default App;

Please help me with this, as I really need to use this in my app.
Thanks :)

@k90s
Copy link

k90s commented Oct 9, 2018

Add a service name will fix it.

httpBridge.start(5561, "service name", (request) => {...

@saberprashant
Copy link
Author

Hey @Kai-Ding , thanks for your answer.
Where do I need to make this service, and what should I put in this service?
Thanks :)

@dsendri
Copy link

dsendri commented Oct 9, 2018

@Kai-Ding thanks for the fix, it works for me

@saberprashant you put the service name as second argument for
httpBridge.start(5561, "SERVICENAME",
at componentWillMount()

@saberprashant
Copy link
Author

Hey @Kai-Ding @dsendri , I tried the suggested fixes, now I am getting this error again which I got in starting, The development server returned response error code: 500.
I tried to solve this error following these links but no luck :
expo/create-react-native-app#401
facebook/react-native#21310

Thanks :)

@saberprashant
Copy link
Author

Hey @Kai-Ding @dsendri , thank you very much guys, finally it is working.
Now, I am facing one more issue, like when I send a POST request with BODY from POSTMAN to my device(where the server is running). it shows response as OK(200), but I don't see data in my console logs, and to see the data I opt for Debug JS Remotely option in the native app menu, and when the debugger opens in my chrome, no console logs are visible. Also, after this, if I send a new request from POSTMAN then request fails.
I don't know what is happening now.
Please help :)

@saberprashant
Copy link
Author

Hey @Kai-Ding @dsendri , thanks once again for your help. Finally, it is working good fr me right now as I also solved some last issues which I mentioned in the above comment,
Thanks everyone for your time :)

@stevenalanstark
Copy link

Please update the readme instructions, I just ran into this same issue caused by following the outdated readme.

@saberprashant
Copy link
Author

Hey @stevenalanstark , somebody has already sent a pull request for the same, I hope they will accept it soon.
Well, if you run into any other issue related to http-bridge then do ping me, as I successfully made this module to work for me.
Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants