对于类未找到错误的android致命异常

时间:2012-05-08 12:02:42

标签: java android authentication cifs jcifs

在上一个问题中,我问过,我已经把所有必要的catch语句都找到了异常。这是另一个。我发布了有例外的问题,因为通过查看它们很容易找到错误。因为我是Android的新手,我发布了这类问题。请参阅下面的代码。它的说法没有上课发现异常。但我已经加载了jcifs包jcifs-1.3.17.jar。我没有得到抛出异常的原因。请看下面:

代码:

package com.android.accesspc;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class userpassActivity extends Activity
{

    EditText userName,userPassword;
    String uName,uPassword,IP,MAC;
    void help(int x)
    {
        userName=(EditText)findViewById(R.id.userpassUsername);
        uName = userName.getText().toString();
        userPassword=(EditText)findViewById(R.id.userpassPassword);
        uPassword = userPassword.getText().toString();
        String url= "smb://" + IP + "/";
        NtlmPasswordAuthentication auth;
        auth= new NtlmPasswordAuthentication(null,uName, uPassword);
        try
        {
            SmbFile a[]=(new SmbFile(url, auth)).listFiles();
            switch(x)
            {
                case 0:
                            Intent intent=new Intent("com.android.accesspc.VIEW");
                            intent.putExtra("IP",IP);
                            intent.putExtra("USERNAME",uName);
                            intent.putExtra("PASSWORD",uPassword);
                            startActivity(intent);  
                            break;
                case 1:
                            //code to switch off the system by checking users log on
                            //need to communicate with darshan's program
                default:
                            finish();
            }
        }
        catch(Exception e)
        {
            Toast.makeText(this,"Username and password is invalid OR",Toast.LENGTH_SHORT).show();
            Toast.makeText(this,"Sytem may be busy OR",Toast.LENGTH_SHORT).show();
            Toast.makeText(this,"Network error",Toast.LENGTH_SHORT).show();
            Toast.makeText(this,"TRY AGAIN!!",Toast.LENGTH_SHORT).show();
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.userpass);
        final Bundle extras = getIntent().getExtras(); 
        if(extras !=null)
        {
            //values from previous activity
            IP = extras.getString("IPfromMacIp");
            MAC = extras.getString("MACfromMacIp");
        }
        Button send=(Button)findViewById(R.id.userpassSendButton);
        send.setOnClickListener(new 
                View.OnClickListener()
        {
            public void onClick(View v) 
            {
                if(extras !=null)
                {
                    help(0);
                }
            }
        });
        Button end=(Button)findViewById(R.id.userpassEndButton);
        end.setOnClickListener(new 
                View.OnClickListener()
        {
            public void onClick(View v) 
            {
                if(extras !=null)
                {
                    help(1);
                }
            }
        });
    }
}

例外:

05-08 17:17:42.905: E/AndroidRuntime(398): FATAL EXCEPTION: main
05-08 17:17:42.905: E/AndroidRuntime(398): java.lang.NoClassDefFoundError: jcifs.smb.NtlmPasswordAuthentication
05-08 17:17:42.905: E/AndroidRuntime(398):  at com.android.accesspc.userpassActivity.help(userpassActivity.java:25)
05-08 17:17:42.905: E/AndroidRuntime(398):  at com.android.accesspc.userpassActivity$1.onClick(userpassActivity.java:73)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.view.View.performClick(View.java:2485)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.view.View.onKeyUp(View.java:4257)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.widget.TextView.onKeyUp(TextView.java:4566)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.view.KeyEvent.dispatch(KeyEvent.java:1280)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.view.View.dispatchKeyEvent(View.java:3855)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
05-08 17:17:42.905: E/AndroidRuntime(398):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1687)
05-08 17:17:42.905: E/AndroidRuntime(398):  at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1120)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.app.Activity.dispatchKeyEvent(Activity.java:2073)
05-08 17:17:42.905: E/AndroidRuntime(398):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1663)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.os.Looper.loop(Looper.java:123)
05-08 17:17:42.905: E/AndroidRuntime(398):  at android.app.ActivityThread.main(ActivityThread.java:3683)
05-08 17:17:42.905: E/AndroidRuntime(398):  at java.lang.reflect.Method.invokeNative(Native Method)
05-08 17:17:42.905: E/AndroidRuntime(398):  at java.lang.reflect.Method.invoke(Method.java:507)
05-08 17:17:42.905: E/AndroidRuntime(398):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-08 17:17:42.905: E/AndroidRuntime(398):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-08 17:17:42.905: E/AndroidRuntime(398):  at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:0)

jar文件放在libs下,而不是lib(如果需要,更改文件夹名称)

答案 1 :(得分:0)

我删除了android dependencies文件夹。现在它的工作