ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

A.Grag's profile - activity

2019-03-21 06:39:29 -0500 received badge  Famous Question (source)
2018-08-27 03:17:08 -0500 marked best answer org.ros.internal.message cannot be cast to std_msgs.String

I'm working recently with Rosjava Kinetic and I have some problems and doubts. I have imported the project to Eclipse to mix it with another project that I have, called PELEA, composed of several modules, to make the message passing through a client-server. Of course, I have a terminal running roscore and a server running inside eclipse. I make the new client and the new message in this way:

public void onStart(final ConnectedNode connectedNode) {

    ServiceClient<std_msgs.String, std_msgs.String> serviceClient;

    try {
         serviceClient = connectedNode.newServiceClient("custom_service", std_msgs.String._TYPE); 
    } catch (ServiceNotFoundException e) {
              throw new RosRuntimeException(e);
    }

     final std_msgs.String request = serviceClient.newMessage(); //ERROR!!
     request.setData("Hello");  

     serviceClient.call(request, new ServiceResponseListener<std_msgs.String>() {

          @Override
        public void onSuccess(std_msgs.String response) {
        connectedNode.getLog().info(String.format("The response is: "));
                    response.getData();}
        @Override
        public void onFailure(org.ros.exception.RemoteException e) {
        throw new RosRuntimeException(e);
        }
    });
}

And I get this error:

Exception in thread "pool-1-thread-3" java.lang.ClassCastException: org.ros.internal.message.$Proxy4 cannot be cast to std_msgs.String
    at org.squeleton.executiondeclarative.ExecutionSqueleton.clientManagement(ExecutionSqueleton.java:591)
    at org.squeleton.executiondeclarative.Client.onStart(Client.java:57)
    at org.ros.internal.node.DefaultNode$5.run(DefaultNode.java:507)
    at org.ros.internal.node.DefaultNode$5.run(DefaultNode.java:504)
    at org.ros.concurrent.EventDispatcher.loop(EventDispatcher.java:43)
    at org.ros.concurrent.CancellableLoop.run(CancellableLoop.java:56)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

So.. I don't know what is the problem, I think it should works..

I appreciate any help, advide or guide.

Thanks a lot and sorry for my bad english.

2018-08-03 06:48:45 -0500 commented answer org.ros.internal.message cannot be cast to std_msgs.String

Thanks for your answer. Finally, I found a way to create a custom message with genjava.

2018-08-02 13:59:20 -0500 received badge  Notable Question (source)
2018-07-31 15:24:51 -0500 received badge  Popular Question (source)
2018-07-31 04:50:40 -0500 received badge  Enthusiast
2018-07-30 17:52:27 -0500 commented question org.ros.internal.message cannot be cast to std_msgs.String

Ok, you are right... sorry.

2018-07-30 16:51:31 -0500 asked a question org.ros.internal.message cannot be cast to std_msgs.String

org.ros.internal.message cannot be cast to std_msgs.String I'm working recently with Rosjava Kinetic and I have some pro

2018-07-27 07:46:02 -0500 received badge  Popular Question (source)
2018-07-27 02:29:06 -0500 edited question Rosjava Unable to instantiate node depending on the class

Rosjava Unable to instantiate node depending the class I'm working recently with Rosjava Kinetic and I have some problem

2018-07-27 00:08:18 -0500 asked a question Rosjava Unable to instantiate node depending on the class

Rosjava Unable to instantiate node depending the class I'm working recently with Rosjava Kinetic and I have some problem