【问题标题】:NoClassDefFound exception while using jcifs library on android 2.3在 android 2.3 上使用 jcifs 库时出现 NoClassDefFound 异常
【发布时间】:2012-05-12 15:21:55
【问题描述】:

我在我的 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;
        }
    }

【问题讨论】:

    标签: java android jcifs


    【解决方案1】:

    在您的项目中添加一个文件夹 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-20
      • 1970-01-01
      相关资源
      最近更新 更多