Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException occurs in running a tutorial code building a simple LwM2M Client #1559

Closed
JeonghyunJoo opened this issue Dec 5, 2023 · 2 comments
Labels
question Any question about leshan

Comments

@JeonghyunJoo
Copy link

JeonghyunJoo commented Dec 5, 2023

Question

I am new to this leshan LwM2M library so please understand me even if my question is a stupid one.

I tried to strictly follow the instructions given by https://github.com/eclipse-leshan/leshan/wiki/Getting-Started-:-Client but I failed to run the tutorial code.

I added specified maven dependencies with 2.0.0-m14 for the leshan library version under the tag in my pom.xml.

I put the example code in my main function, resulting in the following code:

package com.jjh.maven.leshan_client_example;

import org.eclipse.leshan.client.LeshanClient;
import org.eclipse.leshan.client.LeshanClientBuilder;
import org.eclipse.leshan.client.endpoint.LwM2mClientEndpointsProvider;

public class App 
{
    public static void main( String[] args )
    {
    	String endpoint = "..." ; // choose an endpoint name
    	LeshanClientBuilder builder = new LeshanClientBuilder(endpoint);
    	LeshanClient client = builder.build();
    	client.start();
    }
}

It successfully compiled but gave me a NullPointerException with endpointsProvider. The full error message looks like this:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.eclipse.leshan.client.endpoint.LwM2mClientEndpointsProvider.init(org.eclipse.leshan.client.resource.LwM2mObjectTree, org.eclipse.leshan.client.request.DownlinkRequestReceiver, org.eclipse.leshan.client.endpoint.ClientEndpointToolbox)" because "endpointsProvider" is null
	at org.eclipse.leshan.client.LeshanClient.<init>(LeshanClient.java:123)
	at org.eclipse.leshan.client.LeshanClientBuilder.createLeshanClient(LeshanClientBuilder.java:364)
	at org.eclipse.leshan.client.LeshanClientBuilder.build(LeshanClientBuilder.java:328)
	at com.jjh.maven.leshan_client_example.App.main(App.java:13)

In my understanding it seems that I need to call builder.setEndpointsProviders explicitly as builder.endpointsProvider is never initialized with the example code.

Is the tutorial code incomplete? or did I miss something?
If the example code is incomplete, can I ask where I can find a working and concise tutorial code for building a simple client (expecting much simpler code than LeshanClientDemo.java)

Thanks in advance.

@JeonghyunJoo JeonghyunJoo added the question Any question about leshan label Dec 5, 2023
@sbernard31
Copy link
Contributor

Is the tutorial code incomplete? or did I miss something?

Not really the turorial says : "To develop your client you need to use the leshan-client-cf module. To know the last 1.x version."

👆 it is about Leshan version 1.x

For now there is no tutorial for version 2.x. 😞

So

  • either you can live with LWM2M v1.0.x and you can use Leshan v1.x and use the tutorial as it.
  • or if you need LWM2M v1.1.x, you need to go with the in-developement version of Leshan v2.x. and there is no tutorial for now, but you could look at leshan-client-demo as example to fix the tutorial OR look at Add Transport Layer abstraction at Client side. #1323 (for client API).

To learn more about new endpoint provider API (client, server, bootstrap server) : #1025 (comment)

@JeonghyunJoo
Copy link
Author

Thanks @sbernard31

You are right! I could make it run by modifying the Leshan version from 2.0.0-m14 to 1.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Any question about leshan
Projects
None yet
Development

No branches or pull requests

2 participants