rosjava listener.
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 {
@Override
public GraphName getDefaultNodeName() {
return new GraphName.of("rosjava_tutorial_pubsub/listener");
}
@Override
public void onStart(ConnectedNode connectedNode) {
final Log log = connectedNode.getLog();
Subscriber<std_msgs.String> subscriber = connectedNode.newSubscriber("chatter",
std_msgs.String._TYPE);
subscriber.addMessageListener(new MessageListener<std_msgs.String>() {
@Override
public void onNewMessage(std_msgs.String message) {
log.info("I heard: \"" + message.getData() + "\"");
}
});
}
}
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?
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 ...(more)
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.
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.
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.
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.
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?
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.'