Android文件上载进度对话框错误
我上传了这个异步任务文件:Android文件上载进度对话框错误,android,ftp,Android,Ftp,我上传了这个异步任务文件: // ASync Task Begin to perform Billing information class performBackgroundTask extends AsyncTask<Void, Void, Void> { Context context; private ProgressDialog Dialog; protected void onPreExecute() { // here you
// ASync Task Begin to perform Billing information
class performBackgroundTask extends AsyncTask<Void, Void, Void> {
Context context;
private ProgressDialog Dialog;
protected void onPreExecute() {
// here you have place code which you want to show in UI thread like
// progressbar or dialog or any layout . here i am displaying a
// progressDialog with test please wait while loading......
Dialog.setMessage(" please wait while loading............");
Dialog.show();
}
private Context getApplicationContext() {
// TODO Auto-generated method stub
return null;
}
protected Void doInBackground(Void... params) {
// write here the code to download or any background task.
goforIt(); // example call method which will download vedio .
return null;
}
protected void onPostExecute(Void unused) {
Dialog.dismiss();
// the background task is completed .You can do the code here for next
// things
}
public void goforIt() {
FTPClient con = null;
try {
con = new FTPClient();
con.connect(globalconstant.host);
if (con.login(globalconstant.nev, globalconstant.jelszo)) {
con.enterLocalPassiveMode(); // important!
con.setFileType(FTP.BINARY_FILE_TYPE);
String substr = globalconstant.path.substring(4,
globalconstant.path.length());
String filename = substr + "/Festivale.db";
Log.e("TravellerLog :: ", substr + "/Festivale.db");
String data = filename;
FileInputStream in = new FileInputStream(new File(data));
boolean result = con.storeFile("/Festivale.db", in);
in.close();
if (result)
// Toast.makeText(getApplicationContext(),
// "A fájl feltöltve!", Toast.LENGTH_SHORT).show();
Log.v("upload result", "succeeded");
con.logout();
con.disconnect();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
第25行:Dialog.setMessage(“请稍候,正在加载……”)代码>
请帮助我如何制作一个与此相关的进度对话框。
原文是这样的:
private ProgressDialog=新建ProgressDialog(此)
但是这个也有错误
构造函数进程对话框(performBackgroundTask)未定义
您正在做错误的事情,因为对话框从未启动过,只是声明未定义。
另一件事是,每当您定义任何对象/变量名开始字符时,Dialog关键字已经是一个类名(如果字母表必须是小写)。开始字符的所有大写字母都用于类名
编辑的
private ProgressDialog dialog;
protected void onPreExecute() {
dialog = ProgressDialog.show(YourActivity.this, "Processing", "please wait while loading............");
}
在onPostExecution(Void unused)
构造函数ProgressDialog(performBackgroundTask)未定义我应该在参数中写入什么?你应该使用void.09-26 11:50:46.389:E/AndroidRuntime(528):在com.eyecom.festival.performBackgroundTask.onPreExecute(performBackgroundTask.java:25)我认为getApplicationContextdialog=ProgressDialog.show(performBackgroundTask.this,“处理”,加载时请稍候………);错误:类型ProgressDialog中的方法show(上下文、CharSequence、CharSequence)不适用于参数(performBackgroundTask、String、String)
public class async extends AsyncTask<void, void, void>{
private Context context;
ProgressDialog prog;
public async(Context context) {
this.context = context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
prog=new ProgressDialog(context);
prog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
prog.setMax(100);
prog.show();
}
// ...
}
async mTask = new async(context);
mTask.execute();
private ProgressDialog dialog;
protected void onPreExecute() {
dialog = ProgressDialog.show(YourActivity.this, "Processing", "please wait while loading............");
}
onPostExecution(Void unused){
if(dialog!=null)
dialog.dismiss();
}