Rosanswers logo

I am trying to build a listener in rosjava. I used the code found at the rosjava core snapshot documentation and changed the GraphName() to GraphNmae.of(). I also added these lines to the code:

package com.github.rosjava.dude.Listener;(The name of my project is dude as it was given in the tutorial)

import org.ros.rosjava_tutorial_pubsub;

When I build this using catkin_make , I get two errors. THe errors and the code is given below. Can somebody please help me fix this. THanks a ton.

1st error:

/home/uahmed9/rosjava/src/rosjava_foo/dude/src/main/java/com/github/rosjava/dude/Listener.java:2: cannot find symbol symbol : class rosjava_tutorial_pubsub location: package org.ros import org.ros.rosjava_tutorial_pubsub;

The dot between ros and rosjava in the import statement is creating error.

2nd error:

/home/uahmed9/rosjava/src/rosjava_foo/dude/src/main/java/com/github/rosjava/dude/Listener.java:21: cannot find symbol symbol : class of location: class org.ros.namespace.GraphName return new GraphName.of("rosjava_tutorial_pubsub/listener");

The dot between GraphName and of in the getDefaultNodeName() method is creating error. The Code:

package com.github.rosjava.dude.Listener;

import org.ros.rosjava_tutorial_pubsub;

import org.apache.commons.logging.Log;

import org.ros.message.MessageListener;

import org.ros.namespace.GraphName;

import org.ros.node.AbstractNodeMain;

import org.ros.node.ConnectedNode;

import org.ros.node.NodeMain;

import org.ros.node.topic.Subscriber;

public class Listener extends AbstractNodeMain {


public GraphName getDefaultNodeName() {

return new GraphName.of("rosjava_tutorial_pubsub/listener");



public void onStart(ConnectedNode connectedNode) {

final Log log = connectedNode.getLog();

Subscriber<std_msgs.String> subscriber = connectedNode.newSubscriber("chatter", 


subscriber.addMessageListener(new MessageListener<std_msgs.String>() {


  public void onNewMessage(std_msgs.String message) {

    log.info("I heard: \"" + message.getData() + "\"");





Originally posted by uzair on ROS Answers with karma: 87 on 2013-12-27

Post score: 0

Original comments

Comment by Daniel Stonier on 2014-01-01:\

  1. Where did you find the GraphNmae.of(). error?

  2. Where did the code for Listener come from? The current create project script doesn't add this, so not sure where your dot error is coming from.

  3. What do your dependency settings look like?

Comment by uzair on 2014-01-02:
I am sorry for the mistake in pointing the GraphName.of error. I found it in the getDefaultNodeName() method.

I fountd the code for the listener form the rosjava_core 0.1.6 documentation. I created the rosjava package and rosjava project using the tutorials on the rosjava wiki. My projects name was dude and hence I was provided with the Dude.java file when i built my project. I changed the name from Dude.java to Listener.java and also removed the statement public class Dude { } to replace it with public class Listener extends AbstractNodeMain { } and added these lines to the code.

1)package com.github.rosjava.dude.Listener;

2)import org.ros.rosjava_tutorial_pubsub;

For the dependency settings, I opened the gradle file in my project folder and uncommented "compile 'org.ros.rosjava_core:rosjava:[0.1,)' ". Before I did this, I was geting a lot of errors but now it got boiled down to these two.

Comment by Daniel Stonier on 2014-01-02:
Why are you trying to import org.ros.rosjava_tutorial_pubsub? That shouldn't be necessary. I don't think you have that as a dependency either, so that will break your build.

Comment by Daniel Stonier on 2014-01-02:
For reference, you could just copy the working code https://github.com/rosjava/rosjava_core/blob/hydro/rosjava_tutorial_pubsub/src/main/java/org/ros/rosjava_tutorial_pubsub/Listener.java directly from the sources. If that works, and there is differences with the doc code, let us know.

Comment by uzair on 2014-01-02:
THe codes are identical. After I copy the code from github, where do i paste it? I was creating a project called dude following the rosjava tutorials and then making all the changes in the Dude.java class . Today i tried to create a project whith name Listener. The projects name was listener but the name of the class was again Dude.java. How do I make Dude.java to behave like a listener? If I just delete everything in the Dude.java file and paste the listener code, then I am getting an error "Could not copy Manifest.MF". Before this I was trying how i stated above in the question.

Comment by Daniel Stonier on 2014-01-03:
All you should have to do is copy Listener.java in, change the package name in Listener.java to match your folder structure, make sure your build.gradle dependencies match those in the original rosjava_tutorial_pubsub and add rosjava_core to your package.xml.

Comment by uzair on 2014-01-14:
After doing all this, my project builds without any errors. But when i make Listener.java executable and execute the file.. i get a number of errors. THese are the errors i get now ./Listener.java: line 2: package: command not found ./Listener.java: line 4: import: command not found ./Listener.java: line 5: import: command not found ./Listener.java: line 6: import: command not found ./Listener.java: line 7: import: command not found ./Listener.java: line 8: import: command not found ./Listener.java: line 9: import: command not found ./Listener.java: line 10: import: command not found ./Listener.java: line 12: public: command not found ./Listener.java: line 14: @Override: command not found ./Listener.java: line 15: syntax error near unexpected token (' ./Listener.java: line 15: public GraphName getDefaultNodeName() {'

What am i missing?

Comment by uzair on 2014-01-15:
I even tried to download the entire rosjava_core package from github and tried to run the Listener.java class in the pubsub package. When I tried to build, this is all I saw-----####

Running command: "make cmake_check_build_system" in "/home/uahmed9/rosjava_core-hydro/rosjava_tutorial_pubsub/build"

Running command: "make -j4 -l4" in "/home/uahmed9/rosjava_core-hydro/rosjava_tutorial_pubsub/build"

When I tried to execute the Listener.java class i got the following errors-----------./Listener.java: line 1: /bin: Is a directory

./Listener.java: line 2: syntax error near unexpected token (' ./Listener.java: line 2: * Copyright (C) 2011 Google Inc.'

Comment by uzair on 2014-01-20:
I downloaded the rosjava_core package straight from github and made changes in the listener.java class. I build it using the snapshot 1.6 documentation. The listener works fine and receives a statement from python.


1 Answer 1


Rosanswers logo

Does this discussion thread help you uzair?

Originally posted by Daniel Stonier with karma: 3170 on 2014-01-29

This answer was ACCEPTED on the original site

Post score: 0

Original comments

Comment by uzair on 2014-01-29:
yes yes..i was lost. I figured it out. Thanks to you and everybody on the forum. I downloaded the package from github and modified the gradle file to support my external jar instead of creating a new project altogehter.

I have a new problem now. If you can take a look here http://answers.ros.org/question/124096/subscribing-and-publishing-at-the-same-time-in-rosjava/ ..thanks

Comment by uzair on 2014-01-29:
And also I found that package.xml doesnt play any role for rosjava hydro. Its all about the build.gradle file in this version of ros.

Comment by Daniel Stonier on 2014-02-02:
The package.xml allows you to string builds of an entire workspace consisting of multiple gradle repositories together in one build sequence using catkin_make. Under the hood, individual gradle repos and projects are handled by gradle alone.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.