Backendless Support
 
Answered

Illegal argument

Hi there,

I am getting an illegal argument exception if I use the following code. (See attachment)

I already gave my app permission to go on the internet in the manifest file. I also created a DefaultCallback and InitializeBackendless class. Within the InitializeBackendless class I have entered the App ID and the API key it still gave me an error. (See attachment for output). I have commented out the code I attached and I do not get an exception. That is how I know the exception was given from that code. Do you have any ideas what I can do to fix it?

Here is a background of what happened:

Due to permission problems on my pc I had to recreate the application and I also deleted the project from backendless to recreate it. I changed the App ID and API Key in my project from the old key. The ID and the Key is new. I know the problem is not there.

Leave a Comment

Comments (8)

photo
1

Hi Rhinwen,

Is it a Java or Android app? Where do you have Backendless.initApp call?

photo
1

The application is an android app. And I am calling the Backendless.initApp within my InitializeBackendless.java class. And I have add backendless in my gradle (Module: app)

photo
1

Try calling UserIdStorageFactory.instance().init( Context ) before your .loggedInUser() call.

photo
1

Hi it still gives me the same error. By the way where can I read up on the code you gave me? I want to know what it does. I tried here but do not understand the way they present it.

photo
1

Please prepare a minimal verifiable sample so that we could reproduce the problem.

photo
1

Hi I solved the Issue. Thank you for the help.

photo
1

What was the problem?

photo
1

I initialized Backendless in another class using the onCreate method. That worked in the past tho. I just initialized it before the code in the same class instead.

Before:

  1. Backendless.UserService.isValidLogin( new DefaultCallback<Boolean>( LoginScreen.this )
  2. {
  3. @Override
  4. public void handleResponse( Boolean isValidLogin )
  5. {
  6. if( isValidLogin && Backendless.UserService.CurrentUser() == null )
  7. {
  8. // UserIdStorageFactory.instance().init( LoginScreen.this );
  9. String currentUserId = Backendless.UserService.loggedInUser();
  10. if( !currentUserId.equals( "" ) )
  11. {
  12. Backendless.UserService.findById( currentUserId, new DefaultCallback<BackendlessUser>( LoginScreen.this, "Logging in..." )
  13. {
  14. @Override
  15. public void handleResponse( BackendlessUser currentUser )
  16. {
  17. super.handleResponse( currentUser );
  18. Backendless.UserService.setCurrentUser( currentUser );
  19. startActivity( new Intent( getBaseContext(), Welcome_Screen.class ) );
  20. finish();
  21. }
  22. } );
  23. }
  24. }
  25. super.handleResponse( isValidLogin );
  26. }
  27. });

//AFTER:

  1. Backendless.setUrl(InitializeBackendLess.Server_URL);
  2. Backendless.initApp(LoginScreen.this,InitializeBackendLess.App_ID,InitializeBackendLess.API_Key);
  3. Backendless.UserService.isValidLogin( new DefaultCallback<Boolean>( LoginScreen.this )
  4. {
  5. @Override
  6. public void handleResponse( Boolean isValidLogin )
  7. {
  8. if( isValidLogin && Backendless.UserService.CurrentUser() == null )
  9. {
  10. // UserIdStorageFactory.instance().init( LoginScreen.this );
  11. String currentUserId = Backendless.UserService.loggedInUser();
  12. if( !currentUserId.equals( "" ) )
  13. {
  14. Backendless.UserService.findById( currentUserId, new DefaultCallback<BackendlessUser>( LoginScreen.this, "Logging in..." )
  15. {
  16. @Override
  17. public void handleResponse( BackendlessUser currentUser )
  18. {
  19. super.handleResponse( currentUser );
  20. Backendless.UserService.setCurrentUser( currentUser );
  21. startActivity( new Intent( getBaseContext(), Welcome_Screen.class ) );
  22. finish();
  23. }
  24. } );
  25. }
  26. }
  27. super.handleResponse( isValidLogin );
  28. }
  29. });

photo