我試圖從URL加載一些圖像。在AsyncTask中執行函數的錯誤doInBackground
我有一個私人空白,使所有的工作。它的工作原理...但我有一個問題,我想顯示一個對話框的進展,而我的圖像正在加載...
我想與一個AsyncTask但我有一個問題,當執行doInBackground!
這是我的代碼:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new EjecutarTarea().execute();
}
private void Principal() {
//Code to download images from URL
}
public class EjecutarTarea extends AsyncTask<Void, Void, Void> {
protected void onPreExecute() {
dialog = new ProgressDialog(StadioNenaActivity.this);
dialog.setMessage("Cargando..");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();
}
protected Void doInBackground(Void... Unsed) {
Principal(); //i have an error here
return null;
}
protected void onProgressUpdate(Void... unused) {
}
protected void onPostExecute(Void unused) {
dialog.dismiss();
}
}
感謝您的幫助!
這是德日誌中的錯誤...它在我的代碼委託人()的某些部分返回null ....
我不知道爲什麼,當我把本金的OnCreate,它偉大的作品!
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): FATAL EXCEPTION: AsyncTask #1
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): java.lang.RuntimeException: An error occured while executing doInBackground()
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at android.os.AsyncTask$3.done (AsyncTask.java:200)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at java.lang.Thread.run(Thread.java:1096)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): Caused by: java.lang.NullPointerException
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:112)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at org.json.JSONTokener.nextValue(JSONTokener.java:90)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at org.json.JSONArray.<init>(JSONArray.java:87)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at org.json.JSONArray.<init>(JSONArray.java:103)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at Stadio.bacha.stadionena.StadioNenaActivity.Principal(StadioNenaActivity.java:121)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at Stadio.bacha.stadionena.StadioNenaActivity$EjecutarTarea.doInBackground(StadioNenaActivity.java:262)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at Stadio.bacha.stadionena.StadioNenaActivity$EjecutarTarea.doInBackground(StadioNenaActivity.java:1)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at android.os.AsyncTask$2.call(AsyncTask.java:185)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-10 17:56:01.988: ERROR/AndroidRuntime(10907): ... 4 more
當我是這樣的:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Principal();
}
它的工作原理,但它並不顯示對話框進度...
什麼是您的錯誤,打印堆棧跟蹤。空方法通常不會出錯。 – Pyrodante
錯誤似乎是內部主體,所以你可能想向我們展示它的代碼。 – MByD