0
$\begingroup$

Rosanswers logo

Hi~

I'm using the new, pure-java rosjava. I installed ros(diamonback) and rosjava by rosinstall in my ubuntu(lucid). and build rosjava.jar successfully.

I want talk to other node using pubsub tutorial in rosjava. I imported rosjava.jar and other libraries in eclipse project and modified the source as below. (commons-codec-1.3.jar, commons-httpclient-3.1.jar, commons-loggin-1.1.1.jar, dnsjava-2.1.1.jar, guava-r07.jar, junit-4.8.2.jar, mockito-all-1.8.5.jar, netty-3.2.4.Final.jar, rosjava.jar)

When I run below program by java application, I got this error message.

Hello
java.lang.NullPointerException
    at org.ros.Node.<init>(Node.java:95)
    at Hell.main(Hell.java:19)
    at Hell.main(Hell.java:43)

I also tried to debugging with eclipse but, I couldn't debugging with source with this message

Source not found, [Edit Source Lookup Path ...] button.

I tried to connect ros source directory(ros/rosjava/rosjava/src) and include the rosjava source(org.ros), but It also fail to find the source.

Please help me. I'm beginner of the java language. If this question is too sil7ly, Please understand me.

Thanks!


/*
 * Copyright (C) 2011 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

import com.google.common.base.Preconditions;


import org.ros.Node;
import org.ros.NodeConfiguration;
import org.ros.NodeMain;
import org.ros.Publisher;

public class Hell implements NodeMain {
    private Node node;
    /**
     * @param args
     */
    public void main(NodeConfiguration configuration){
        Preconditions.checkState(node == null);
        Preconditions.checkNotNull(configuration);
        try {
          node = new Node("talker", configuration);
          Publisher<org.ros.message.std_msgs.String> publisher =
              node.createPublisher("chatter", org.ros.message.std_msgs.String.class);
          int seq = 0;
          while (true) {
            org.ros.message.std_msgs.String str = new org.ros.message.std_msgs.String();
            str.data = "Hello world! " + seq++;
            publisher.publish(str);
            Thread.sleep(1000);
          }
        } catch (Exception e) {
          if (node != null) {
            node.getLog().fatal(e);
          } else {
            e.printStackTrace();
          }
        }
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("Hello");
        
        Hell h = new Hell();
        NodeConfiguration node_cfg = new NodeConfiguration();
        h.main(node_cfg);
    }

    public void shutdown() {
        node.shutdown();
        node = null;
      }

}


Originally posted by hughie on ROS Answers with karma: 71 on 2011-06-15

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I see a couple of issues:

First, you should pull the latest version. Your line numbers don't match up with my source.

To view the source, you should be able to attach the source to rosjava.jar as you described. Make sure you select "External folder" and select the "rosjava/src" folder not the "org" folder beneath it.

Finally, I believe your problem is that you have an invalid NodeConfiguration. Admittedly, the error message could be better.

Try using: NodeConfiguration node_cfg = NodeConfiguration.createDefault();


Originally posted by damonkohler with karma: 3838 on 2011-06-16

This answer was ACCEPTED on the original site

Post score: 6


Original comments

Comment by damonkohler on 2011-06-20:
Please accept the answer if it works for you. Thanks!

Comment by hughie on 2011-06-20:
Now, everything is fine. Thanks.

$\endgroup$

Your Answer

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