0

Iam making an android app which will authenticate a user into an active directory. Currently, I have followed a tutorial on http://www.windowsazure.com/en-us/documentation/articles/mobile-services-android-get-started-users/.

I only need to authenticate a user at this point. So I have done the following:-

import com.microsoft.windowsazure.mobileservices.MobileServiceApplication;
import com.microsoft.windowsazure.mobileservices.MobileServiceAuthenticationProvider;
import com.microsoft.windowsazure.mobileservices.MobileServiceClient;
import com.microsoft.windowsazure.mobileservices.MobileServiceUser;
import com.microsoft.windowsazure.mobileservices.ServiceFilterResponse;
import com.microsoft.windowsazure.mobileservices.UserAuthenticationCallback;

    public static MobileServiceClient mobileServiceClient;
    public MobileServiceUser _user;
    MobileServiceClient mCLient;
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        web = (WebView)findViewById(R.id.webSignin);


        web.getSettings().setJavaScriptEnabled(true);
        web.loadUrl("https://login.microsoftonline.com/login.srf?wa=wsignin1%2E0&rpsnv=2&ct=1390811289&rver=6%2E1%2E6206%2E0&wp=MBI&wreply=https%3A%2F%2Fwww7679%2Esharepoint%2Ecom%2F%5Flayouts%2F15%2Flanding%2Easpx%3FSource%3Dhttps%253A%252F%252Fzevenseascom%252D11%252Esharepoint%252Eemea%252Emicrosoftonline%252Ecom%252F%255Fforms%252Fdefault%252Easpx&lc=16393&id=500046&guests=1");


        authenticate();



    }

    private void authenticate()
    {
        // TODO Auto-generated method stub
        mCLient.login(MobileServiceAuthenticationProvider.Google, new UserAuthenticationCallback()
        {

            @Override
            public void onCompleted(MobileServiceUser user, Exception exception,
                    ServiceFilterResponse response) 
            {
                // TODO Auto-generated method stub
                if(exception == null)
                {
                    createAndShowDialog(String.format("You are now logged in - %1$2s", user.getUserId()),"Success");
                    Intent myIntent = new Intent(MainActivity.this, Directory.class);
                    startActivity(myIntent);

                }
                else
                {
                     createAndShowDialog("You must log in. Login Required", "Error");
                }
            }
        });
    }

But i get the following error:-

java.lang.NoClassDefFoundError: com.microsoft.windowsazure.mobileservices.MobileServiceAuthenticationProvider
01-28 10:34:04.732: E/AndroidRuntime(2150):     at com.example.activedirectory.MainActivity.authenticate(MainActivity.java:68)

Any help is appreciated

user3146095
  • 419
  • 2
  • 7
  • 25
  • Please ensure that you have added correct Library – Luc Jan 28 '14 at 05:21
  • @Jack Duong Thanks for the response. But can you please elaborate as Iam new to windows azure authentication – user3146095 Jan 28 '14 at 05:24
  • Do you have the correct import statements – Ogen Jan 28 '14 at 05:28
  • If you have library, please check project -> properties -> check your library, re-build – Luc Jan 28 '14 at 05:34
  • @JackDuong I do have my library in the project and tried clean-> rebuild. But still the same issue. The app doesnt even start – user3146095 Jan 28 '14 at 05:39
  • The error NoClassDefFoundError occurs when could not find correct library, could you show me that library? – Luc Jan 28 '14 at 05:51
  • @JackDuong I tried the solution by Krrishnaaaa. The error seems to resolve but now I get another error `01-28 11:21:49.716: E/AndroidRuntime(4704): Caused by: java.lang.NullPointerException 01-28 11:21:49.716: E/AndroidRuntime(4704): at com.example.activedirectory.MainActivity.authenticate(MainActivity.java:68) 01-28 11:21:49.716: E/AndroidRuntime(4704): at com.example.activedirectory.MainActivity.onCreate(MainActivity.java:50) ` – user3146095 Jan 28 '14 at 06:00
  • Please init for MobileServiceClient mCLient; You just declare, not init. May be it is mClient = new MobileServiceClient(...); – Luc Jan 28 '14 at 06:04
  • @JackDuong I initialized the mCLient with my app url and id. Now I get an error:-`01-28 11:56:50.974: E/AndroidRuntime(6793): java.lang.NoClassDefFoundError: com.google.gson.GsonBuilder 01-28 11:56:50.974: E/AndroidRuntime(6793): at com.microsoft.windowsazure.mobileservices.MobileServiceClient.createMobileServiceGsonBuilder(MobileServiceClient.java:136) 01-28 11:56:50.974: E/AndroidRuntime(6793): at com.microsoft.windowsazure.mobileservices.MobileServiceClient.(MobileServiceClient.java:187) ` – user3146095 Jan 28 '14 at 06:30
  • You should download and add this library: https://code.google.com/p/google-gson/downloads/list – Luc Jan 28 '14 at 06:32
  • @JackDuong Did it. Thanks. Can you put an answer so that I can accept it – user3146095 Jan 28 '14 at 06:40
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/46198/discussion-between-jack-duong-and-user3146095) – Luc Jan 28 '14 at 06:53
  • You are welcome. Please accept it to help other people who gets the same error. – Luc Jan 28 '14 at 06:54

2 Answers2

0

Have you tried this solution.
Project Properties>Java Build Path>Order and Import tab and check the libraries you are using.

It seems that ADT update 22, you have to do this manually: Libraries do not get added to APK anymore after upgrade to ADT 22.

Community
  • 1
  • 1
Krrishnaaaa
  • 689
  • 11
  • 23
  • I tried doing it.. As mentioned my library wasnt checked. I marked it and then tried running the app but still the same error – user3146095 Jan 28 '14 at 05:49
  • I resolved that error. But now I get this error `01-28 11:21:49.716: E/AndroidRuntime(4704): Caused by: java.lang.NullPointerException 01-28 11:21:49.716: E/AndroidRuntime(4704): at com.example.activedirectory.MainActivity.authenticate(MainActivity.java:68) 01-28 11:21:49.716: E/AndroidRuntime(4704): at com.example.activedirectory.MainActivity.onCreate(MainActivity.java:50) ` – user3146095 Jan 28 '14 at 06:04
  • You haven't initialized `mClient` that's why you are getting `NullPointerException` – Krrishnaaaa Jan 28 '14 at 06:42
0

Please init for MobileServiceClient mCLient; You just declare, not init. May be it is

mClient = new MobileServiceClient(...); 

And with error:

    -01-28 11:56:50.974: E/AndroidRuntime(6793): 
java.lang.NoClassDefFoundError: com.google.gson.GsonBuilder 01-28 11:56:50.974: E/AndroidRuntime(6793): at com.microsoft.windowsazure.mobileservices.MobileServiceClient.createMobileServic‌​eGsonBuilder(MobileServiceClient.java:136) 01-28 11:56:50.974: 
E/AndroidRuntime(6793): at com.microsoft.windowsazure.mobileservices.MobileServiceClient.<init>(MobileServi‌​ceClient.java:187)

just add library: GSON

Luc
  • 2,800
  • 2
  • 25
  • 46