0
$\begingroup$

Rosanswers logo

I am trying to write a node that is supposed to run on an android device. Here is the code I have; basically I want to create a node when a button is clicked (I know it is not a good idea to do it on the UI thread, but this is just for testing purposes). The node itself extends MainNode and publishes a string to a topic.

Button send_btn;
TalkerNode node;
NodeMainExecutor exec;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    send_btn = (Button)findViewById(R.id.send_button);
    send_btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v)
        {
            send_btn.setText(R.string.sending);
            String masterUri = "http://192.168.1.35:11311";
            URI uri;
            NodeConfiguration node_conf;
            try 
            {
                uri = new URI(masterUri);
                String host = InetAddressFactory.newNonLoopback().getHostAddress();
                node_conf = NodeConfiguration.newPublic(host);
                node_conf.setNodeName("android_node");
                node_conf.setMasterUri(uri);
            } 
            catch (URISyntaxException e) 
            {
                e.printStackTrace();
                return;
            }
            node = new TalkerNode();
            
            exec = DefaultNodeMainExecutor.newDefault();
            exec.execute(node, node_conf);
        }
    });
}

Everything compiles, the program on the device starts, but it crashes at the line:

String host = InetAddressFactory.newNonLoopback().getHostAddress();

with error - NoClassDefFoundError for the class com.google.common.collect.Lists. Moreover, I tried to set the host manually as the ip of the device, but then the program crashes on the next line:

node_conf = NodeConfiguration.newPublic(host);

with error - NoClassDefFoundError for the class com.google.common.base.Preconditions. I tried importing com.google.common.*, but it didn't help. Any clue how I can fix it? I am using android API level 10 and have pulled rosjava from the repository yesterday.


Originally posted by svepe on ROS Answers with karma: 36 on 2012-02-04

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

I found out that I need guava, so I have just put it and this solved the problem, but now I am getting SocketException at the same line.


Originally posted by svepe with karma: 36 on 2012-02-04

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$
0
$\begingroup$

Rosanswers logo

I'm not sure if this will help, but here's an example of how I'm currently creating a node using DefaultNodeFactory with the newest rosjava:

NodeMainExecutor nodeMainExecutor = DefaultNodeMainExecutor.newDefault(); 
node = new DefaultNodeFactory(nodeMainExecutor.getScheduledExecutorService()).newNode(config);

Originally posted by selliott with karma: 51 on 2012-02-06

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by svepe on 2012-02-07:
It still crashes... I guess I will have to wait a bit until they write up some documentation.

Comment by selliott on 2012-02-17:
Have you also updated your appmanandroid library? Parts of that library were updated to match with the newest rosjava. Wthout actually seeing your errors, I'd say that outdated appmanandroid parts could cause errors with NodeRunner and DefaultNodeFactory.

$\endgroup$

Your Answer

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