NoClassDefFound exception when using jcifs library on Android 2.3

I am using jcifs-1.3.17.jar library in my android application.

The following part of the code works well on the android 1.6 simulator, but does not work on 2.3 and 3.0.

Follow the warning in the logcat 2.3 simulator when starting the application.

05-03 10:41:43.105: E/dalvikvm(338): Could not find class 'jcifs.smb.NtlmPasswordAuthentication', referenced from method myPackage.getFile

And get the following exception when creating the NtlmPasswordAuthentication object.

05-03 10:49:59.765: E/AndroidRuntime(338): java.lang.NoClassDefFoundError: jcifs.smb.NtlmPasswordAuthentication

Can anyone say what I'm missing?

My function

public boolean getFile(String url) 
    {
        try 
        {

            String  name="server1";//my windows username
            String  password="password1";//my windows password

            SmbFile dir=null;
            url = url.toLowerCase();

            if (!url.startsWith("smb://") )
                url = "smb://" + url;

            SmbFile file = null;
            try 
            {
                NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, name, password);
                file = new SmbFile(url, auth);
                SmbFileInputStream in = new SmbFileInputStream( file );

                File gpxfile = null;
                File root = Environment.getExternalStorageDirectory();
                gpxfile = new File(root, file.getName());
                gpxfile.delete();
                gpxfile.createNewFile();
                FileOutputStream out = new FileOutputStream(gpxfile);

                long t0 = System.currentTimeMillis();

                byte[] b = new byte[8192];
                int n, tot = 0;
                long t1 = t0;
                while(( n = in.read( b )) > 0 ) {
                    out.write( b, 0, n );
                    tot += n;
                }


            } 
            catch (Exception e1) 
            {

            }


            return true;
        } 
        catch (Exception e) 
        {
            return false;
        }
    }
+3
source share
1 answer

Add the libs folder to your project and copy your entire jar file into it.

follow these instructions

so right click on your project -> create a folder called libs

and follow this step in

 right click (on libs folder) -->import-->File System-->browse to select your jar file and hit finish and run you project.

thereafter

 right click on the project --> Built Path-->java built path-->add jars select your jar file from your libs folder
+3
source

All Articles