我在这里使用AsyncTask:
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()代码:
@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;
}
错误日志:
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)
答案 0 :(得分:1)
“println需要一条消息”NPE来自这里:
catch (Exception e) {
Log.e("Error: ", e.getMessage());
}
e.getMessage()
可以返回null
,您无法记录普通null
。
将其更改为例如
catch (Exception e) {
Log.e("Error", "", e);
}
使用完整的堆栈跟踪记录异常。在此之后,更新问题,以便我们可以首先解决导致异常的任何原因。
WindowLeaked
问题是早期问题的结果 - 应用程序在没有正确解除对话框的情况下崩溃。这不是你应该担心的事情。