而在Android上使用2.3 JCIFS库NoClassDefFound例外 [英] NoClassDefFound exception while using jcifs library on android 2.3

查看:281
本文介绍了而在Android上使用2.3 JCIFS库NoClassDefFound例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JCIFS-1.3.17.jar库在我的Andr​​oid应用程序。

code的下面这段行之有效的Andr​​oid 1.6的模拟器,但未能对2.3和3.0。

获取以下2.3模拟器logcat的警告应用程序启动时。

  10月5日至3日:41:43.105:E / dalvikvm(338):找不到类的jcifs.smb.NtlmPasswordAut​​hentication,从法myPackage.getFile引用

和得到下面的异常,同时创造NtlmPasswordAut​​hentication对象。

  10月5日至3日:49:59.765:E / AndroidRuntime(338):java.lang.NoClassDefFoundError的:jcifs.smb.NtlmPasswordAut​​hentication

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

我的功能

 公共布尔的GetFile(字符串URL)
    {
        尝试
        {            字符串名称=服务器1; //我的Windows用户名
            字符串密码=密码1; //我的Windows密码            SmbFile DIR = NULL;
            URL = url.toLowerCase();            如果(url.startsWith(SMB://!))
                URL =SMB://+网址;            SmbFile文件= NULL;
            尝试
            {
                NtlmPasswordAut​​hentication AUTH =新NtlmPasswordAut​​hentication(NULL,名称,密码);
                文件=新SmbFile(URL,验证);
                SmbFileInputStream在=新SmbFileInputStream(文件);                文件gpxfile = NULL;
                文件根= Environment.getExternalStorageDirectory();
                gpxfile =新的文件(根,file.getName());
                gpxfile.delete();
                gpxfile.createNewFile();
                FileOutputStream中出=新的FileOutputStream(gpxfile);                长T0 = System.currentTimeMillis的();                字节[] B =新的字节[8192];
                INT N,TOT = 0;
                长T1 = T0;
                而((N = in.read(b))的大于0){
                    out.write(B,0,N);
                    TOT + = N;
                }
            }
            赶上(例外E1)
            {            }
            返回true;
        }
        赶上(例外五)
        {
            返回false;
        }
    }


解决方案

添加文件夹库在您的项目,并复制所有jar文件如此说。

按照下列指示

在你的项目,所以右键 - >创建一个名称的文件夹的

,然后按照这个步骤

 右键点击(在libs文件夹) -  GT;进口 - >文件系统 - >浏览选择jar文件并点击完成并运行你的项目。

之后

 右键单击项目 - >内置路径 - >内置的java路径 - >添加罐从你的libs文件夹中选择您的jar文件

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

Following piece of code works well on android 1.6 simulator but fails on 2.3 and 3.0.

Get following warning in logcat of 2.3 simulator when application starts.

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

And get following exception while creating NtlmPasswordAuthentication object.

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

Can anybody tell, what I am missing?

My function is

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

解决方案

Add a folder libs in your project and copy all your jar file in that.

follow these instructions

so right click on your project -->create a folder with name 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.

after that

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

这篇关于而在Android上使用2.3 JCIFS库NoClassDefFound例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆