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

running rosjava pub/sub tutorial as NodeRunner

asked 2011-12-26 05:14:33 -0500

dejanpan gravatar image

Hi there, I took a look at the rosjava">pub and sub tutorials today and tried to get them to run through the NodeRunner class.

I thus created the below file with the main, placed it into the folder with the [Talker|Listener].java files and successfully compiled it.

package org.ros.tutorials.pubsub;
import org.ros.node.NodeRunner;
import org.ros.node.Node;
import org.ros.node.NodeMain;
import org.ros.node.NodeConfiguration;
import org.ros.node.DefaultNodeRunner;
import org.ros.tutorials.pubsub.Talker;
public class MyRobot 
  public static void main(String[] args) 
    NodeMain nodeMain =  new Talker();
    //        NodeConfiguration nodeConfiguration;
    NodeConfiguration nodeConfiguration = NodeConfiguration.newPrivate();
    NodeRunner nodeRunner = DefaultNodeRunner.newDefault();, nodeConfiguration);

The problem however is that I am now NOT able to successfully execute it. I tried with "java MyRobot" command (in targer/classed folder) but all I am getting back is the following error message:

Exception in thread "main" java.lang.NoClassDefFoundError: MyRobot
Caused by: java.lang.ClassNotFoundException: MyRobot
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
Could not find the main class: MyRobot. Program will exit.

If anyone could tell me why the class is not being found I'd greatly appreciate it.

best, D.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2012-01-17 01:20:21 -0500

damonkohler gravatar image

First, the rosjava_tutorial_pubsub has been updated to use NodeMainExecutor. I suggest pulling the latest version.

Second, you'll need to run rosjava nodes using the rosjava_bootsrap script. It will take care of constructing the correct class path to load your node. The error you received is due to an incorrect class path.

rosrun rosjava_bootstrap <pkg> <node_class>

edit flag offensive delete link more

answered 2012-01-24 20:35:16 -0500

Markus Eich gravatar image

In my case the sample talker/listener is derived from NodeMain, not NodeMain executer. I pulled my sources from hg Is there another version?

edit flag offensive delete link more


Please reply to answers in comments, not as new answers. You should not derive from NodeMainExecutor. Make sure to pull the latest sources (they change frequently) and take another look at the rosjava_tutorial_pubsub package.
damonkohler gravatar image damonkohler  ( 2012-01-25 05:12:19 -0500 )edit

answered 2012-02-04 09:33:02 -0500

svepe gravatar image

I am trying to write a node that is supposed to run on an android device. Everything compiles, the program on the device starts, but it crashes with the same error - NoClassDefFoundError. Any clue how I can fix it? I am using android API level 10 and have pulled rosjava from the repository literally a few hours ago.

edit flag offensive delete link more


Please ask this as a new question.
ahendrix gravatar image ahendrix  ( 2012-02-04 19:28:14 -0500 )edit
svepe gravatar image svepe  ( 2012-02-04 21:00:09 -0500 )edit

Question Tools


Asked: 2011-12-26 05:14:33 -0500

Seen: 1,083 times

Last updated: Feb 04 '12