Как говорится в заголовке приложения, при сбое приложения появляется диалоговое окно создания прогресса. Контекст передается классу async через конструктор.Ошибка выполнения Диалоговое окно в async-задаче
public class URLImageReader extends AsyncTask<URL, Void, Bitmap> {
ImageView MyView = null;
Activity context = null;
private OnTaskComplete mlistener;
public URLImageReader(Activity context,OnTaskComplete mlistener, ImageView view){
this.context = context;
this.mlistener = mlistener;
MyView = view;
}
ProgressDialog dialog = new ProgressDialog(context);
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog.setMessage("Loading...");
dialog.show();
}
@Override
protected Bitmap doInBackground(URL... params) {
Bitmap image = null;
try {
URL url= params[0];
image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e){
e.printStackTrace();
}
return image;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
mlistener.callBackFunction(bitmap);
MyView.setImageBitmap(bitmap);
dialog.dismiss();
}
}
03-04 07:59:18.531 14860-14860/youth_stories.com.youth_stories E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: youth_stories.com.youth_stories, PID: 14860
java.lang.RuntimeException: Unable to start activity ComponentInfo{youth_stories.com.youth_stories/youth_stories.com.youth_stories.Home}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:154)
at android.app.AlertDialog.<init>(AlertDialog.java:109)
at android.app.ProgressDialog.<init>(ProgressDialog.java:77)
at youth_stories.com.youth_stories.URLImageReader.<init>(URLImageReader.java:30)
at youth_stories.com.youth_stories.Home.onCreate(Home.java:144)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-04 07:59:19.704 14860-14860/youth_stories.com.youth_stories I/Process﹕ Sending signal
Какая ошибка? – Fahim
может показать мне, как это получить? Диалог ProgressDialog = новый ProgressDialog (getApplicationContext()); это в домашнем классе? –
вставьте свой logcat – virendrao