Ask Your Question
2

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 https://rosjava.googlecode.com/hg/rosjava_tutorial_pubsub/src/main/java/org/ros/tutorials/pubsub/">pub and sub tutorials today and tried to get them to run through the NodeRunner class.

I thus created the below MyRobot.java 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 com.google.common.base.Preconditions;
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();
    nodeRunner.run(nodeMain, nodeConfiguration);
    nodeRunner.shutdown();
  }
}

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 java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
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
1

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 run.py 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 run.py <pkg> <node_class>

edit flag offensive delete link more
0

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 https://rosjava.googlecode.com/hg. Is there another version?

edit flag offensive delete link more

Comments

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 imagedamonkohler ( 2012-01-25 05:12:19 -0500 )edit
-1

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

Comments

Please ask this as a new question.
ahendrix gravatar imageahendrix ( 2012-02-04 19:28:14 -0500 )edit
svepe gravatar imagesvepe ( 2012-02-04 21:00:09 -0500 )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

Stats

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

Seen: 919 times

Last updated: Feb 04 '12