1

在我提出的上一个问题中,我放置了所有必要的 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)
4

2 回答 2

0

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

于 2012-05-08T12:06:27.773 回答
0

我删除了 android 依赖项文件夹。现在它的工作

于 2012-06-01T09:06:35.583 回答