简体   繁体   中英

Crash in android while executing AsyncTask doInBackground()

AsyncTask i used here:

class AsynTaskApply extends AsyncTask<String, String, String> {

                Bitmap im1,im2,im3,im4,im5,im6,im7,im8,im9,im10;
        MyProgressDailog myPreogress1;
        Bitmap b1=frames1.this.tempBitmap;

        protected void onPreExecute() {
            super.onPreExecute();
            try {
            myPreogress1=new MyProgressDailog(frames1.this, "Applying...");
            myPreogress1.setCancelable(false);
            myPreogress1.show();
            }
            catch(Exception localExp){
                localExp.printStackTrace();

            }
        }

DoInBackground() code:

@Override
protected String doInBackground(String... f_url) {

    try {       if("Original".equals(selectFitem) || selectFint==R.drawable.orginal){
                    if (ImageEffect_one != null) 
                        if (ImageEffect_one != null) 
                        {
                              frames1.this.ImageEffect_one.recycle();
                              frames1.this.ImageEffect_one = null;
                                    System.gc();
                        }   
                im1= frames1.this.tempBitmap;       }

        else if("Hue".equals(selectFitem) || selectFint==R.drawable.hue){
            if (ImageEffect_one != null) 
                {     frames1.this.ImageEffect_one.recycle();
                      frames1.this.ImageEffect_one = null;
                            frames1.this.v3 = null;
                            System.gc();
                }            
                        frames1.this.v3 = Eeffects.dohuefilter(b1,3);
                        im4= frames1.this.v3;
                }

        else if("Bright".equals(selectFitem) || selectFint==R.drawable.bright){
            if (ImageEffect_one != null) 
                {
                      frames1.this.ImageEffect_one.recycle();
                      frames1.this.ImageEffect_one = null;
                            frames1.this.v3 = null;
                            System.gc();
                }            
                        frames1.this.v3 = Eeffects.dobrihtness(b1, 40);
                        im5= frames1.this.v3;

                }
        //Shading =Contrast name used
        else if("Contrast".equals(selectFitem) || selectFint==R.drawable.contrast){
            if (ImageEffect_one != null) 
                {     frames1.this.ImageEffect_one.recycle();
                      frames1.this.ImageEffect_one = null;
                            frames1.this.v3 = null;
                            System.gc();
                }            
                        frames1.this.v3 = Eeffects.applyShadingFilter(b1, -30000);
                        im6= frames1.this.v3;
                        }

        else if("Tint".equals(selectFitem) || selectFint==R.drawable.tint){
            if (ImageEffect_one != null) 
                {     frames1.this.ImageEffect_one.recycle();
                      frames1.this.ImageEffect_one = null;
                            frames1.this.v3 = null;
                            System.gc();
                }            
                        frames1.this.v3 = Eeffects.dotint(b1, 60);
                        im7= frames1.this.v3;
                         }
        //do Noise =blur name used
        else if("Blur".equals(selectFitem) || selectFint==R.drawable.blur){
            if (ImageEffect_one != null) 
                {     frames1.this.ImageEffect_one.recycle();
                      frames1.this.ImageEffect_one = null;
                            frames1.this.v3 = null;
                            System.gc();
                }            
                        frames1.this.v3 = Eeffects.donoise(b1);
                        im8= frames1.this.v3;
                         }

        else if("Saturation".equals(selectFitem) || selectFint==R.drawable.saturation){
            if (ImageEffect_one != null) 
                {     frames1.this.ImageEffect_one.recycle();
                      frames1.this.ImageEffect_one = null;
                            frames1.this.v3 = null;
                            System.gc();
                }            
                        frames1.this.v3 = Eeffects.dosaturation(b1);
                        im9= frames1.this.v3;
                        }


        else if("Sepia".equals(selectFitem) || selectFint==R.drawable.orginal){
            if (ImageEffect_one != null) 
                {
                      frames1.this.ImageEffect_one.recycle();
                      frames1.this.ImageEffect_one = null;
                            frames1.this.v3 = null;
                            System.gc();
                }            
                        frames1.this.v3 = Eeffects.applySepiaEffect(b1, 50, 1.5, 0.6, 0.12);
                        im10= frames1.this.v3;
                        }



         } catch (Exception e) {
        Log.e("Error: ", e.getMessage());
    }

    return null;
}

Error Log:

02-21 00:24:34.666: E/AndroidRuntime(30718): FATAL EXCEPTION: AsyncTask #3
02-21 00:24:34.666: E/AndroidRuntime(30718): java.lang.RuntimeException: An error occured while executing doInBackground()
02-21 00:24:34.666: E/AndroidRuntime(30718):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
02-21 00:24:34.666: E/AndroidRuntime(30718):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
02-21 00:24:34.666: E/AndroidRuntime(30718):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
02-21 00:24:34.666: E/AndroidRuntime(30718):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
02-21 00:24:34.666: E/AndroidRuntime(30718):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-21 00:24:34.666: E/AndroidRuntime(30718):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
02-21 00:24:34.666: E/AndroidRuntime(30718):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
02-21 00:24:34.666: E/AndroidRuntime(30718):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
02-21 00:24:34.666: E/AndroidRuntime(30718):    at java.lang.Thread.run(Thread.java:856)
02-21 00:24:34.666: E/AndroidRuntime(30718): Caused by: java.lang.NullPointerException: println needs a message
02-21 00:24:34.666: E/AndroidRuntime(30718):    at android.util.Log.println_native(Native Method)
02-21 00:24:34.666: E/AndroidRuntime(30718):    at android.util.Log.e(Log.java:297)
02-21 00:24:34.666: E/AndroidRuntime(30718):    at com.moblications.andyteam.wallframes.frames1$AsynTaskApply.doInBackground(frames1.java:558)
02-21 00:24:34.666: E/AndroidRuntime(30718):    at com.moblications.andyteam.wallframes.frames1$AsynTaskApply.doInBackground(frames1.java:1)
02-21 00:24:34.666: E/AndroidRuntime(30718):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-21 00:24:34.666: E/AndroidRuntime(30718):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
02-21 00:24:34.666: E/AndroidRuntime(30718):    ... 5 more
02-21 00:24:35.010: E/SpannableStringBuilder(30718): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
02-21 00:24:35.010: E/SpannableStringBuilder(30718): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
02-21 00:24:42.260: E/WindowManager(30718): Activity com.moblications.andyteam.wallframes.frames1 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4254c558 that was originally added here
02-21 00:24:42.260: E/WindowManager(30718): android.view.WindowLeaked: Activity com.moblications.andyteam.wallframes.frames1 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4254c558 that was originally added here
02-21 00:24:42.260: E/WindowManager(30718):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:397)
02-21 00:24:42.260: E/WindowManager(30718):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:311)
02-21 00:24:42.260: E/WindowManager(30718):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
02-21 00:24:42.260: E/WindowManager(30718):     at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
02-21 00:24:42.260: E/WindowManager(30718):     at android.view.Window$LocalWindowManager.addView(Window.java:556)
02-21 00:24:42.260: E/WindowManager(30718):     at android.app.Dialog.show(Dialog.java:277)
02-21 00:24:42.260: E/WindowManager(30718):     at com.moblications.andyteam.wallframes.frames1$AsynTaskApply.onPreExecute(frames1.java:426)
02-21 00:24:42.260: E/WindowManager(30718):     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
02-21 00:24:42.260: E/WindowManager(30718):     at android.os.AsyncTask.execute(AsyncTask.java:534)
02-21 00:24:42.260: E/WindowManager(30718):     at com.moblications.andyteam.wallframes.frames1$1.onItemSelected(frames1.java:253)
02-21 00:24:42.260: E/WindowManager(30718):     at android.widget.AdapterView.fireOnSelected(AdapterView.java:892)
02-21 00:24:42.260: E/WindowManager(30718):     at android.widget.AdapterView.access$200(AdapterView.java:49)
02-21 00:24:42.260: E/WindowManager(30718):     at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:860)
02-21 00:24:42.260: E/WindowManager(30718):     at android.os.Handler.handleCallback(Handler.java:615)
02-21 00:24:42.260: E/WindowManager(30718):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-21 00:24:42.260: E/WindowManager(30718):     at android.os.Looper.loop(Looper.java:137)
02-21 00:24:42.260: E/WindowManager(30718):     at android.app.ActivityThread.main(ActivityThread.java:4895)
02-21 00:24:42.260: E/WindowManager(30718):     at java.lang.reflect.Method.invokeNative(Native Method)
02-21 00:24:42.260: E/WindowManager(30718):     at java.lang.reflect.Method.invoke(Method.java:511)
02-21 00:24:42.260: E/WindowManager(30718):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
02-21 00:24:42.260: E/WindowManager(30718):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
02-21 00:24:42.260: E/WindowManager(30718):     at dalvik.system.NativeStart.main(Native Method)

The "println needs a message" NPE comes from here:

catch (Exception e) {
    Log.e("Error: ", e.getMessage());
}

e.getMessage() can return null and you cannot log a plain null .

Change it to eg

catch (Exception e) {
    Log.e("Error", "", e);
}

to log the exception with full stacktrace. After this, update the question so we can address whatever causes the exception in the first place.

The WindowLeaked problem is a consequence of an earlier problem - the app crashed without not properly dismissing a dialog. It's not something you should be worried at this point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM