3

我在我的 android 应用程序中使用 jcifs-1.3.17.jar 库。

以下代码在 android 1.6 模拟器上运行良好,但在 2.3 和 3.0 上失败。

应用程序启动时在 2.3 模拟器的 logcat 中收到以下警告。

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

并在创建 NtlmPasswordAuthentication 对象时出现以下异常。

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

谁能告诉我,我错过了什么?

我的功能是

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;
        }
    }
4

1 回答 1

4

在您的项目中添加一个文件夹 libs 并在其中复制所有 jar 文件。

按照这些说明

所以右键单击您的项目->创建一个名为libs的文件夹

并按照此步骤

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

在那之后

 right click on the project --> Built Path-->java built path-->add jars select your jar file from your libs folder
于 2012-05-03T05:53:45.867 回答