- 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/
问题很简单:我正在寻找一种优雅的使用方式 CompletableFuture#exceptionally与 CompletableFuture#supplyAsync 一起.这是行不通的: priva
对于 Web 服务,我们通常使用 maven-jaxb2-plugin 生成 java bean,并在 Spring 中使用 JAXB2 编码。我想知道如何处理 WSDL/XSD 中声明的(SOAP-
这个问题已经有答案了: Array index out of bound behavior (10 个回答) 已关闭 8 年前。 我对下面的 C 代码感到好奇 int main(){
当在类的开头使用上下文和资源初始化 MediaPlayer 对象时,它会抛出 NullPointer 异常,但是当在类的开头声明它时(因此它是 null),然后以相同的方式初始化它在onCreate方
嘿 我尝试将 java 程序连接到 REST API。 使用相同的代码部分,我在 Java 6 中遇到了 Java 异常,并且在 Java 8 中运行良好。 环境相同: 信任 机器 unix 用户 代
我正在尝试使用 Flume 和 Hive 进行 Twitter 分析。为了从 twitter 获取推文,我在 flume.conf 文件中设置了所有必需的参数(consumerKey、consumer
我在 JavaFX 异常方面遇到一些问题。我的项目在我的 Eclipse 中运行,但现在我的 friend 也尝试访问该项目。我们已共享并直接保存到保管箱文件夹中。但他根本无法让它发挥作用。他在控制台
假设我使用 blur() 事件验证了电子邮件 ID,我正在这样做: $('#email').blur(function(){ //make ajax call , check if dupli
我这样做是为了从 C 代码调用非托管函数。 pCallback 是一个函数指针,因此在托管端是一个委托(delegate)。 [DllImport("MyDLL.dll")] public stati
为什么这段代码是正确的: try { } catch(ArrayOutOfBoundsException e) {} 这是错误的: try { } catch(IOException e) {} 这段
我遇到了以下问题:有导出函数的DLL。 代码示例如下:[动态链接库] __declspec(dllexport) int openDevice(int,void**) [应用] 开发者.h: __de
从其他线程,我知道我们不应该在析构函数中抛出异常!但是对于下面的例子,它确实有效。这是否意味着我们只能在一个实例的析构函数中抛出异常?我们应该如何理解这个代码示例! #include using n
为什么需要异常 引出 public static void main(String[
1. Java的异常机制 Throwable类是Java异常类型的顶层父类,一个对象只有是 Throwable 类的(直接或者间接)实例,他才是一个异常对象,才能被异常处理机制识别。JDK中内
我是 Python 的新手,我对某种异常方法的实现有疑问。这是代码(缩写): class OurException(Exception): """User defined Exception"
我已经创建了以下模式来表示用户和一组线程之间的关联,这些线程按他们的最后一条消息排序(用户已经阅读了哪些线程,哪些没有): CREATE TABLE table(user_id bigint, mes
我正在使用 Python 编写一个简单的自动化脚本,它可能会在多个位置引发异常。在他们每个人中,我都想记录一条特定的消息并退出程序。为此,我在捕获异常并处理它(执行特定的日志记录操作等)后引发 Sys
谁能解释一下为什么这会导致错误: let xs = [| "Mary"; "Mungo"; "Midge" |] Array.iter printfn xs 虽然不是这样: Array.iter pr
在我使用 Play! 的网站上,我有一个管理部分。所有 Admin Controller 都有一个 @With 和一个 @Check 注释。 断开连接后,一切正常。连接后,每次加载页面(任何页面,无论
我尝试连接到 azure 表存储并添加一个对象。它在本地主机上工作得很好,但是在我使用的服务器上我得到以下异常及其内部异常: Exception of type 'Microsoft.Wind
我是一名优秀的程序员,十分优秀!