- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我运行下面的代码时出现以下异常。这是一个android代码,用于访问远程windows pc。它用于下载、上传和删除。当我运行这段代码时,它会抛出验证异常。但我不知道实际的错误。有人可以找到错误吗?
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)
代码:
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();
}
}
}
最佳答案
我注意到您正在使用 Java CIFS 库。我的猜测是您没有使用它的 Android 版本,而是您刚刚在项目中删除了标准 jar。这行不通。您需要为 Android 重新编译它。
另外,你不应该将你的包命名为 com.android.test(不要在其中包含 android 这个词)。
关于android程序的java致命异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10493951/
我的电脑正确配置了 SSH,我在尝试克隆存储库时遇到了这个错误: 我运行这个命令来克隆存储库 git clone ssh://git-codecommit.us-west-2.amazonaws.co
我试图下载android源代码。但是遇到了一个问题。 # repo init -u https://android.googlesource.com/platform/manifest fatal:
尝试运行我 4 年前开发的 Rails 4 项目,从那时起我一直在维护,我遇到了下一个错误,该错误在启动时卡住了应用程序: machine stack overflow in critical reg
这个问题在这里已经有了答案: psql: FATAL: role "postgres" does not exist (32 个答案) 关闭上个月。 我正在设置 Postgresql 以与 Rail
我正在创建新分支并尝试推送该分支(我尝试了以下命令): git push --all -u git push origin NewBranch 但在这两种情况下我都会收到此错误: Permission
我尝试克隆这个 repo 几次,但得到了同样的错误。是不是因为它太大而我的连接速度很慢? $ git clone https://git01.codeplex.com/typescript Cloni
我正在尝试使用 http://danielmiessler.com/study/git/#website 设置 git管理我的网站。 我已经到了指令的最后一步:git push website +ma
当我使用快速启动方法安装Eucalyptus云时,我看到安装失败。以后检查日志文件时,遇到以下错误。 最佳答案 错误消息是: Invalid gateway due to subnet/netmask
黄色, 我尝试按照以下步骤设置选项“在没有用户名和密码的情况下访问(推送到)Github”。 https://medium.com/@amanze.ogbonna/accessing-pushing-
我很难用 postgres 设置 django。 这是我的设置.py: DATABASES = { 'default': { 'ENGINE': 'django.db.back
当我尝试从实时实例服务器访问数据库时出现此错误。有谁知道原因吗? 最佳答案 可能是你的硬盘没有可用空间 关于PostgreSQL:致命:XX000:无法写入初始化文件,我们在Stack Overflo
我正在尝试连接到我的 PostgreSQL 服务器,但 psql 提示我没有有效的客户端证书。以下是我创建证书的方式: 自签名服务器证书: openssl req -new -text -nodes
我团队中的其他人创建了一个新的 git 分支,提交并推送到我们使用的常用远程。当我尝试检查这个分支时,我得到了这个: % git checkout 12382 fatal: Cannot switch
我正在尝试让 TravisCI 自动部署我的 Hakyll 静态站点,根据 this guide . 这是我的存储库的设置方式。我有我的源代码分支,其中包含我的 hakyll 和 Markdown 文
尝试提交时 git commit -a -m "Huge update" 我明白了 fatal: could not parse HEAD Error When Committing 看完fatal:
我想在我的 flutter 应用程序上使用 fcm,所以在创建 firebase 控制台并在我的 gradle 中安装了一些依赖项之后,如下所示: build.gradle:项目 dependenci
我是 GIT 的初学者,现在遇到了一个大问题。我在另一台 PC 上提交并推送了一些文件,现在在我的家用 PC 上,git 坏了。 请看下面: $ git status fatal: failed to
我想从 github 上克隆一个项目到我的电脑上 D:\Projects> git clone https://github.com/***/***.git 但是在下载的时候,出现了几个致命的错误:
所以我尝试使用以下命令获取opencv_contrib: $ git clone https://github.com/Itseez/opencv_contrib 这给了我以下错误: fatal: d
这是我在pod文件中使用的行 pod'SDWebImage','〜> 3.8' 以前是 pod'SDWebImage','〜> 3.7' 我尝试了以下 pod安装 pod更新和 pod更新'SDWeb
我是一名优秀的程序员,十分优秀!