2012-09-26 19 views
0

我得到這個的AsyncTask文件上傳:Android的文件上傳進度對話框錯誤

// 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(); 
     } 
    } 

} 

但總是有誤差meassage,這樣的:

09-26 11:30:30.538: E/AndroidRuntime(456): java.lang.NullPointerException 
09-26 11:30:30.538: E/AndroidRuntime(456): at com.eyecom.festivale.performBackgroundTask.onPreExecute(performBackgroundTask.java:25) 
... 

第25行:Dialog.setMessage(" please wait while loading............");

請幫我如何製作一個適用於此的進度對話框。 原來是這樣的:

private ProgressDialog Dialog = new ProgressDialog(this);

,但與此有錯誤太多,

The constructor ProgressDialog(performBackgroundTask) is undefined

+0

看到我的編輯答案。 – rajeshwaran

回答

1

你正在做的Dialog從來沒有啓動過它,只是宣佈不了定義。 另一件事Dialog關鍵字已經是一個類名,只要你定義了任何對象/變量名的起始字符,如果字母表必須是小寫的。開始字符的所有大寫都用於類名稱。

Editted

private ProgressDialog dialog; 

protected void onPreExecute() { 
    dialog = ProgressDialog.show(YourActivity.this, "Processing", "please wait while loading............"); 
} 

onPostExecution(Void unused)

onPostExecution(Void unused){ 
    if(dialog!=null) 
     dialog.dismiss(); 
} 
+0

11月9日至26日:50:46.389:E/AndroidRuntime(528):\t在com.eyecom.festivale.performBackgroundTask.onPreExecute(performBackgroundTask.java:25) – David

+0

我覺得有一個rroblem與getApplicationContext – David

+0

答案更新檢查 – Pratik

1
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(); 
    } 

    // ... 
} 

然後實例化並運行此的AsyncTask:

async mTask = new async(context); 
mTask.execute(); 
+0

構造函數ProgressDialog(performBackgroundTask)未定義 – David

+0

應該在params中寫什麼?或讓它參數? – David

+0

讓它params.you應該使用void。 – rajeshwaran