Ask Your Question

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");, new ServiceResponseListener<std_msgs.String>() {

        public void onSuccess(std_msgs.String response) {
        connectedNode.getLog().info(String.format("The response is: "));
        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(
    at org.squeleton.executiondeclarative.Client.onStart(
    at org.ros.internal.node.DefaultNode$
    at org.ros.internal.node.DefaultNode$
    at org.ros.concurrent.EventDispatcher.loop(
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$

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


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 image jayess  ( 2018-07-30 17:10:53 -0600 )edit

Ok, you are right... sorry.

A.Grag gravatar image A.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 image jayess  ( 2018-07-30 18:07:25 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

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 and first, I think you are mixing the concepts of messages and topics with services.

edit flag offensive delete link more


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

A.Grag gravatar image A.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


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

Seen: 464 times

Last updated: Aug 02 '18