Ask Your Question
0

org.ros.internal.message cannot be cast to std_msgs.String

asked 2018-07-30 16:51:31 -0600

A.Grag gravatar image

updated 2018-07-30 17:08:48 -0600

jayess gravatar image

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.

edit retag flag offensive close merge delete

Comments

Just so you know, the <pre> and <code> tags don't do a very good job at marking up code and terminal output. It's usually easier to highlight the text then click on the 101010 button instead. That way your code is marked up with syntax highlighting.

jayess gravatar imagejayess ( 2018-07-30 17:10:53 -0600 )edit

Ok, you are right... sorry.

A.Grag gravatar imageA.Grag ( 2018-07-30 17:52:27 -0600 )edit

It's not a problem, just for reference for the next time that you ask a question :)

jayess gravatar imagejayess ( 2018-07-30 18:07:25 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-08-02 13:40:01 -0600

jubeira gravatar image

@A.Grag std_msgs.String is a standard message, and you are dealing with service clients in that piece of code.

I suggest you to take a look at https://github.com/rosjava/rosjava_co... and http://wiki.ros.org/rosjava_build_too... first, I think you are mixing the concepts of messages and topics with services.

edit flag offensive delete link more

Comments

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

A.Grag gravatar imageA.Grag ( 2018-08-03 06:48:45 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-07-30 16:51:31 -0600

Seen: 202 times

Last updated: Aug 02 '18