سؤال

i got the following exception when i run the code below. this is an android code, to access remote windows pc. it is used for download, upload and delete.when i run this code its throwing verification exception.but i dont know the actual error. can someone pls find the error?

05-08 11:51:25.885: E/AndroidRuntime(517): FATAL EXCEPTION: main
05-08 11:51:25.885: E/AndroidRuntime(517): java.lang.VerifyError: com.android.test.t
05-08 11:51:25.885: E/AndroidRuntime(517):  at java.lang.Class.newInstanceImpl(Native Method)
05-08 11:51:25.885: E/AndroidRuntime(517):  at java.lang.Class.newInstance(Class.java:1409)
05-08 11:51:25.885: E/AndroidRuntime(517):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-08 11:51:25.885: E/AndroidRuntime(517):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
05-08 11:51:25.885: E/AndroidRuntime(517):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-08 11:51:25.885: E/AndroidRuntime(517):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-08 11:51:25.885: E/AndroidRuntime(517):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-08 11:51:25.885: E/AndroidRuntime(517):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 11:51:25.885: E/AndroidRuntime(517):  at android.os.Looper.loop(Looper.java:123)
05-08 11:51:25.885: E/AndroidRuntime(517):  at android.app.ActivityThread.main(ActivityThread.java:3683)
05-08 11:51:25.885: E/AndroidRuntime(517):  at java.lang.reflect.Method.invokeNative(Native Method)
05-08 11:51:25.885: E/AndroidRuntime(517):  at java.lang.reflect.Method.invoke(Method.java:507)
05-08 11:51:25.885: E/AndroidRuntime(517):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-08 11:51:25.885: E/AndroidRuntime(517):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-08 11:51:25.885: E/AndroidRuntime(517):  at dalvik.system.NativeStart.main(Native Method)

code:

package com.android.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileInputStream;
import jcifs.smb.SmbFileOutputStream;
import android.app.ListActivity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

class Helper extends AsyncTask<Integer, Void, Void> 
{
//  private t one=new t();
    private SmbFile dfile;
    private String dfilepath;
    private SmbFile dfolder;
    private String dfolderpath;
    private File ufolder;
    private SmbFile ufoldersmb;
    private NtlmPasswordAuthentication auth;
    private int upstate=0;
    private int downstate=0;
    private Context context;
    private ArrayList<SmbFile> smbArray=new ArrayList<SmbFile>();
    private String ext;
    private int tasknumber;
    private String taskname;
    public Context getcontext()
    {
        return context;
    }
    public int gettasknumber()
    {
        return tasknumber;
    }
    public String gettaskname()
    {
        return taskname;
    }
    public int getupstate() 
    {
        return upstate;
    }
    public int getdownstate() 
    {
        return downstate;
    }
    public void setdfile(SmbFile a) 
    {
        this.dfile = a;
    }
    public void setdfilepath(String b) 
    {
        this.dfilepath = b;
    }
    public void setdfolder(SmbFile c) 
    {
        this.dfolder = c;
    }
    public void setdfolderpath(String d) 
    {
        this.dfolderpath = d;
    }
    public void setufolder(File g) 
    {
        this.ufolder = g;
    }
    public void setufoldersmb(SmbFile h) 
    {
        this.ufoldersmb = h;
    }
    public void setauthentication(NtlmPasswordAuthentication i) 
    {
        this.auth = i;
    }
    public void setupstate(int j) 
    {
        upstate = j;
    }
    public void setdownstate(int k) 
    {
        downstate = k;
    }
    public void setcontext(Context l) 
    {
        context = l;
    }
    public void setarraysmb(SmbFile m) 
    {
        this.smbArray.add(m);
    }
    public void setextstorage(String n) 
    {
        this.ext=n;
    }
    public void settasknumber(int o) 
    {
        this.tasknumber=o;
    }
    public void settaskname(String p) 
    {
        this.taskname=p;
    }
    @Override
    protected Void doInBackground(Integer... params) 
    {
        //check flag to execute exactly method
        switch (params[0]) 
        {
            case 0:
                downloadTask();
                break;
            case 1:
                //Toast.makeText(context, "AccessPC Upload task "+tasknumber+" Started", Toast.LENGTH_LONG).show();
                uploadFolder(ufolder,ufoldersmb);
                break;
            default:break;
        }
        return null;
    }
    void downloadFile(SmbFile dfile,String dpath)
    {   
        StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath()); 
        long blockSize = statFs.getBlockSize();
        long freeSize = statFs.getFreeBlocks()*blockSize;
        try
        {
            if(!((freeSize-dfile.length())<0))
            {
                SmbFileInputStream din=new SmbFileInputStream(dfile);
                FileOutputStream dout=new FileOutputStream(dpath);
                int c;
                while((c=din.read())!=-1)
                {
                    dout.write(c);
                }
                if (din != null) 
                {
                    din.close();
                }
                if (dout != null) 
                {
                    dout.close();
                }
            }
            else
            {
                //Toast.makeText(context, "AccessPC Download Task failed ",Toast.LENGTH_LONG).show();
            }
        }
        catch(Exception e)
        {
            //Toast.makeText(context, "AccessPC Download Task failed "+e,Toast.LENGTH_LONG).show();
        }
    }
    void downloadFolder(SmbFile dfolder,String dfolderpath)
    {
        try 
        {
            dfolderpath=dfolderpath+dfolder.getName();
            if(!(new File(dfolderpath)).exists())
            {
                (new File(dfolderpath)).mkdir();
            }
            SmbFile[] temp=dfolder.listFiles(); 
            if(temp.length==0)
            {
                return;
            }
            for(SmbFile m:temp)
            {
                if(m.isFile())
                {
                    downloadFile(m,dfolderpath+m.getName());
                }
                else
                {
                    downloadFolder(m,dfolderpath);
                }
            }
        } 
        catch (Exception e) 
        {
            //Toast.makeText(context, "AccessPC Download Task failed "+e,Toast.LENGTH_LONG).show();
        }
    }
    void uploadFile(File ufile,SmbFile ufilesmb)
    {
        try
        {
            FileInputStream uin=new FileInputStream(ufile);
            SmbFile tempSmb=new SmbFile(ufilesmb.getPath()+ufile.getName(),auth);
            SmbFileOutputStream uout=new SmbFileOutputStream(tempSmb);
            int c;
            while((c=uin.read())!=-1)
            {
                uout.write(c);
            }
            if (uin != null)
            {
                uin.close();
            }
            if (uout != null) 
            {
                uout.close();
            }
        }
        catch(Exception e)
        {
            //Toast.makeText(context, "AccessPC Upload Task failed "+e, Toast.LENGTH_LONG).show();
        }
    }
    void uploadFolder(File ufolder,SmbFile ufoldersmb)
    {
        try 
        {
            SmbFile tempSmb=new SmbFile(ufoldersmb.getPath()+ufolder.getName()+"/",auth);
            if(!tempSmb.exists())
            {
                tempSmb.mkdir();
            }
            File[] ftemp=ufolder.listFiles();
            if(ftemp.length==0)
            {
                setupstate(2);
                return;
            }
            for(File m:ftemp)
            {
                if(m.isFile())
                {
                    uploadFile(m,tempSmb);
                }
                else
                {
                    uploadFolder(m,tempSmb);
                }
            }
        } 
        catch (Exception e) 
        {
            //Toast.makeText(context, "AccessPC Upload Task failed "+e,Toast.LENGTH_LONG).show();
        }
    }
    void downloadTask()
    {
        //Toast.makeText(context, "AccessPC download task "+tasknumber+" Started", Toast.LENGTH_LONG).show();
        try 
        {
            for(SmbFile m:smbArray)
            {
                if(m.isFile())
                {       
                    setdfile(m);
                    setdfilepath(ext+m.getName());
                    downloadFile(dfile,dfilepath);
                }
                else
                {
                    setdfolder(m);
                    setdfolderpath(ext);
                    downloadFolder(dfolder,dfolderpath);
                }
            } 
            setdownstate(2);
        }
        catch (Exception e) 
        {
            //Toast.makeText(context,"Download error "+e,Toast.LENGTH_LONG).show();
        }
    }   
    @Override
    protected void onPostExecute(Void result) 
    {
        if(upstate==2)
        {
            setupstate(0);
            //Toast.makeText(context, "AccessPC "+taskname+" task "+tasknumber+" Finished", Toast.LENGTH_LONG).show();
        }
        if(downstate==2)
        {
            setdownstate(0);
            //Toast.makeText(context, "AccessPC "+taskname+" task "+tasknumber+" Finished", Toast.LENGTH_LONG).show();
        }   
    }
    @Override
    protected void onCancelled() {
        // TODO Auto-generated method stub
        if(!isCancelled())
            cancel(true);
    }

}

class imageCheckBoxAdapter extends ArrayAdapter<String> implements OnClickListener
{
    private final Context context;
    private final ArrayList<String> values;
    private final Map< String, SmbFile> obj;
    private ArrayList<Boolean> checks=new ArrayList<Boolean>();
    public imageCheckBoxAdapter(Context context,ArrayList<String> values,Map< String, SmbFile>obj) 
    {
        super(context, R.layout.row_checkbox, values);
        this.context = context;
        this.values = values;
        this.obj=obj;
        for (int i = 0; i < values.size(); i++) 
        {
            checks.add(i, false);
        }
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.row_checkbox, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.text1_check);
        CheckBox chk = (CheckBox) rowView.findViewById(R.id.checkBox1);
        textView.setText(values.get(position));
        ImageView imageView = (ImageView) rowView.findViewById(R.id.icon_image_check);
        try
        {
            if((obj.get(values.get(position)).isFile()))
            {
                imageView.setImageResource(R.drawable.view_file_icon);
            }
            else
            {
                imageView.setImageResource(R.drawable.view_folder_icon);
            }
        }
        catch (Exception e) 
        {
            Toast.makeText(context,"Network error "+e,Toast.LENGTH_LONG).show();
        }
        chk.setTag(Integer.valueOf(position));
        // Set a listener for the checkbox
        chk.setOnClickListener(this);
        //Sets the state of CB, since we have the list of checked CB
        chk.setChecked(checks.get(position));
        return rowView;
    }
    @Override
    public void onClick(View view) 
    {
        Integer index = (Integer)view.getTag();
        boolean state = checks.get(index.intValue());
        checks.set(index.intValue(), !state);
    }
    boolean getter(int i)
    {
       return checks.get(i);
    }
}

class imageAdapter extends ArrayAdapter<String>
{
    private final Context context;
    private final ArrayList<String> values;
    private final Map< String, SmbFile> obj;
    public imageAdapter(Context context,ArrayList<String> values,Map< String, SmbFile> obj) 
    {
        super(context, R.layout.row, values);
        this.context = context;
        this.values = values;
        this.obj=obj;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.row, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.text1);
        textView.setText(values.get(position));
        ImageView imageView = (ImageView) rowView.findViewById(R.id.icon_image);
        try
        {
            if((obj.get(values.get(position)).isFile()))
            {
                imageView.setImageResource(R.drawable.view_file_icon);
            }
            else
            {
                imageView.setImageResource(R.drawable.view_folder_icon);
            }
        }
        catch (Exception e) 
        {
            Toast.makeText(context,"Network error "+e,Toast.LENGTH_LONG).show();
        }
        return rowView;
    }
}

public class t extends ListActivity
{
    String ip="127.0.0.1",name="Deepak",password="       ";
    String url;
    NtlmPasswordAuthentication auth;
    Map< String, SmbFile> map=new HashMap< String, SmbFile>();
    SmbFile previous=null,current=null;
    imageCheckBoxAdapter object=null;
    String extStorage=Environment.getExternalStorageDirectory()+"/t/";
    ArrayList<Helper> helpobject=new ArrayList<Helper>();
    int uptask=0;
    int downtask=0;
    int level=0;
    int MENU_STATE=0;
    final int MENU_GENERAL=0;
    final int MENU_DOWNLOAD=1;
    final int MENU_UPLOAD=2;
    final int MENU_DELETE=3;
    final int DOWNLOAD1=41;
    final int DOWNLOAD2=42;
    final int UPLOAD=43;
    final int DELETE1=45;
    final int DELETE2=46;
    final int QUIT=47;
    final int CANCEL=48;
    final int FINISH=49;

    Map< String, SmbFile> listMap(SmbFile obj)
    {
        Map< String, SmbFile> list_map=new HashMap< String, SmbFile>();
        int i;
        try
        {
            SmbFile a[]=obj.listFiles();
            for(i=0;i<a.length;i++)
            {
                if(!a[i].isHidden())
                {
                    list_map.put( a[i].getName(), a[i] ); 
                }
            }
            return list_map;
        }
        catch(SmbException e)
        {
            Toast.makeText(this,"cannot list files "+e,Toast.LENGTH_LONG).show();
            return null;
        }

    }   
    Map< String, SmbFile> display(SmbFile obj)
    {
        Map< String, SmbFile> display_map=new HashMap< String, SmbFile>();
        ArrayList<String> smbName=new ArrayList<String>();
        display_map=listMap(obj);
        Set<String> keys = display_map.keySet();
        for(String key:keys)
        {
            smbName.add(key);
        }
        setListAdapter(new imageAdapter(this, smbName,display_map));
        return display_map;
    }
    Map< String, SmbFile> display_check(SmbFile obj)
    {
        Map< String, SmbFile> display_map=new HashMap< String, SmbFile>();
        ArrayList<String> smbName=new ArrayList<String>();
        display_map=listMap(obj);
        Set<String> keys = display_map.keySet();
        for(String key:keys)
        {
            smbName.add(key);
        }
        object= new imageCheckBoxAdapter(this, smbName,display_map);
        setListAdapter(object);
        return display_map;
    }   
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) 
    {
        if(MENU_STATE==MENU_GENERAL)
        {
            menu.clear();
            menu.add(0, DOWNLOAD1, 0, "Download");
            menu.add(0, UPLOAD, 0, "Upload");
            menu.add(0, DELETE1, 0, "Delete");
            menu.add(0, QUIT, 0, "Quit");
            menu.add(0, FINISH, 0, "Finish");
        }
        else
        {
            if(MENU_STATE==MENU_DOWNLOAD)
            {
                menu.clear();
                menu.add(0, DOWNLOAD2, 0, "Download");
                menu.add(0, CANCEL, 0, "Cancel");
            }
            else
            {
                if(MENU_STATE==MENU_DELETE)
                {
                    menu.clear();
                    menu.add(0, DELETE2, 0, "Delete");
                    menu.add(0, CANCEL, 0, "Cancel");
                }
            }
        }
        return super.onPrepareOptionsMenu(menu);
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
        switch(item.getItemId())
        {
            case DOWNLOAD1:
                            MENU_STATE=MENU_DOWNLOAD;
                            map=display_check(current);
                            return true;
            case UPLOAD:
                            if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
                            {
                                if(current.getShare()==null)
                                {
                                    Toast.makeText(this,"UPLOAD FAILED",Toast.LENGTH_LONG).show();
                                }
                                else
                                {
                                    File f=new File(extStorage);
                                    Helper help=new Helper();
                                    helpobject.add(help);
                                    help.setufolder(f);
                                    help.setufoldersmb(current);
                                    help.setauthentication(auth);
                                    help.setupstate(1);
                                    help.settasknumber(uptask);
                                    uptask++;
                                    help.settaskname("Upload");
                                    help.setcontext(this.getApplicationContext());
                                    help.execute(1);
                                }
                            }
                            else
                            {
                                Toast.makeText(this,"UPLOAD FAILED--NO SD CARD FOUND",Toast.LENGTH_LONG).show();
                            }
                            return true;
        case DELETE1:
                            MENU_STATE=MENU_DELETE;
                            map=display_check(current);
                            return true;
        case QUIT:
                            for(Helper k:helpobject)
                            {
                                if(k.getStatus()==AsyncTask.Status.RUNNING||k.getStatus()==AsyncTask.Status.PENDING)
                                {
                                    k.cancel(true);
                                }
                            }
                            int countm=0;
                            for(Helper k:helpobject)
                            {
                                if(k.isCancelled())
                                {
                                    countm++;
                                }
                            }
                            if(countm==helpobject.size())
                            Toast.makeText(this,"All download and upload tasks cancelled",Toast.LENGTH_LONG).show();
                            return true;
        case DOWNLOAD2:  
                            if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
                            {
                                int tempcount=0;
                                for(int i=0;i<object.getCount();i++)
                                {
                                    if(object.getter(i)==true)
                                    {
                                        tempcount++;
                                    }
                                }
                                if(tempcount==0)
                                {
                                    Toast.makeText(this,"Please choose atleast one item for download!!",Toast.LENGTH_LONG).show();
                                }
                                else
                                {
                                    Helper help=new Helper();
                                    helpobject.add(help);
                                    help.settasknumber(downtask);
                                    downtask++;
                                    help.settaskname("Download");
                                    help.setcontext(this.getApplicationContext());
                                    help.setextstorage(extStorage);
                                    help.setdownstate(1);
                                    for(int i=0;i<object.getCount();i++)
                                    {
                                        if(object.getter(i)==true)
                                        {
                                            help.setarraysmb(map.get(object.getItem(i)));
                                        }
                                    }
                                    help.execute(0);
                                }
                            }
                            else
                            {
                                Toast.makeText(this,"DOWNLOAD FAILED--NO SD CARD FOUND",Toast.LENGTH_LONG).show();
                            }                   
                            return true;
        case DELETE2:
                            for(int i=0;i<object.getCount();i++)
                            {
                                if(object.getter(i)==true)
                                {
                                    try 
                                    {
                                        map.get(object.getItem(i)).delete();
                                    } 
                                    catch (Exception e) 
                                    {
                                        Toast.makeText(this,"cannot be deleted "+e,Toast.LENGTH_LONG).show();
                                    }
                                }
                            }
                            return true;
        case CANCEL:
                            MENU_STATE=MENU_GENERAL;
                            map=display(current);
                            return true;
        case FINISH:
                            finish();
        default:
                            return super.onOptionsItemSelected(item);
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        File abc=new File(Environment.getExternalStorageDirectory()+"/t/");
        if(!abc.exists())
        {
            abc.mkdir();
        }
        url= "smb://" + ip + "/";
        auth = new NtlmPasswordAuthentication(null, name, password);
        try 
        {
            SmbFile dir = new SmbFile(url, auth);
            current=dir;
            map=display(dir);
        } 
        catch (Exception e) 
        {
            Toast.makeText(this,"Network error "+e,Toast.LENGTH_LONG).show();
        }

    }
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) 
    {
        super.onListItemClick(l, v, position, id);
        Object o=this.getListAdapter().getItem(position);
        String keyword=o.toString();
        Set<String> keys = map.keySet();
        for(String key:keys)
        {
            if(keyword==key)
            {
                SmbFile temp=map.get(key);
                try
                {
                    if(temp.isDirectory())
                    {
                        try
                        {
                            previous= new SmbFile(map.get(key).getParent(), auth);
                            level=level+1;
                        }
                        catch(Exception e)
                        {
                            Toast.makeText(this,"Network error "+e,Toast.LENGTH_LONG).show();
                        }
                        current=map.get(key);
                        map=display(map.get(key));
                    }
                }
                catch(Exception e)
                {
                    Toast.makeText(this,"you can't open this directory "+e,Toast.LENGTH_LONG).show();
                }
            }
        }   
    }
    @Override
    public void onBackPressed() 
    {
        MENU_STATE=MENU_GENERAL;
        if(level>=1)
        {
            level=level-1;
            current=previous;
            map=display(previous);
            try
            {
                previous=new SmbFile(previous.getParent(), auth);
            }
            catch (Exception e) 
            {
                Toast.makeText(this,"Network error "+e,Toast.LENGTH_LONG).show();
            }   
        }
        else
        {
            level=0;
            super.onBackPressed();
        }   
    }
}
هل كانت مفيدة؟

المحلول

I've noticed that you are using Java CIFS library. My guess is that you aren't using an Android version of it, but instead you have just dropped the standard jar in your project. This won't work. You need to recompile it for Android.

Also, you shouldn't name your package com.android.test (don't include the word android in it).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top