1

Java Add User

(04/11/2016 22:21:08 отредактировано tkabeary)

Тема: Java Add User

Greetings

I'm running the Java API and working with the example code.
I'm attaching the code.
I can get a list of units, but when I try to add a user (or a unit), I get the following:


Session ID:01bf9f9a1c999513bdf3d88d1b7ef5a6
Adding USER:
com.wialon.item.User@15317ed
Unknown error
java.lang.NullPointerException
        at UnitsSearchExample$3.onFailure(UnitsSearchExample.java:780)
        at com.wialon.remote.handlers.ResponseHandler.onFailure(ResponseHandler.java:47)
        at com.wialon.remote.RemoteHttpClient$RemoteCallback.processStringAnswer(RemoteHttpClient.java:247)
        at com.wialon.remote.RemoteHttpClient$RemoteCallback.done(RemoteHttpClient.java:229)
        at com.wialon.remote.ApacheSdkHttpClient$HttpRequest.run(ApacheSdkHttpClient.java:190)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Unknown error
java.lang.NullPointerException
        at UnitsSearchExample$3.onFailure(UnitsSearchExample.java:780)
        at com.wialon.remote.handlers.ResponseHandler.onFailure(ResponseHandler.java:47)
        at com.wialon.remote.RemoteHttpClient$RemoteCallback.processStringAnswer(RemoteHttpClient.java:247)
        at com.wialon.remote.RemoteHttpClient$RemoteCallback.done(RemoteHttpClient.java:229)
        at com.wialon.remote.ApacheSdkHttpClient$HttpRequest.run(ApacheSdkHttpClient.java:190)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Logout successfully
---------------------------------------------------
Here's the code stub:
    session.createUser(session.getCurrUser(), "AddTest", "foobar", (long) 0x0001, new SearchResponseHandler() {
            @Override
            public void onSuccessSearch(Item... items) {
                super.onSuccessSearch(items);
                // Search succeed
                System.out.println("Create User was successful");
                // printUnitsNames(items);
                logout();
            }

            @Override
            public void onFailure(int errorCode, Throwable throwableError) {
                super.onFailure(errorCode, throwableError);
                // search item failed, print error
                System.out.println(Errors.getErrorText(errorCode));
                throwableError.printStackTrace();
                logout();
            }
        });

2

Java Add User

Re: Java Add User

tkabeary
Looking at your stacktrace I think that problem is in your onFailure method at line

throwableError.printStackTrace();

You don't check if the throwableError variable is not null.
As well as in your code occurs onFailure method call I can conclude that user has not been created. To resolve the issue you need to check the errorCode variable's value and compare it with list of errors.

Mobile Development
Gurtam