Android- java.lang.IllegalArgumentException

我已经看过这个问题 。 但无法弄清楚问题是什么。 我在我的ImageSyncReciever类中使用BackgroundMail在后台发送电子邮件。 但是当发送电子邮件时,我的应用程序崩溃,同时给我以下错误

致命exception:主要过程:com.thumbsol.accuratemobileassetsmanagament,PID:7480 java.lang.IllegalArgumentException:View = com.android.internal.policy.impl.PhoneWindow $ DecorView {300e55de VE …. R ….. I 。 在android.view.WindowManagerImpl的android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:353)的android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:434)上没有附加到窗口管理器的0,0-0,0}。在android.app.Dialog.dismissDialog(Dialog.java:382)的android.app.Dialog.dismiss(Dialog.java:365)中删除ViewImmediate(WindowManagerImpl.java:116),位于com.creativityapps.gmailbackgroundlibrary.BackgroundMail $ SendEmailTask​​.onPostExecute (BackgroundMail.java:302)at com.creativityapps.gmailbackgroundlibrary.BackgroundMail $ SendEmailTask​​.onPostExecute(BackgroundMail.java:265)at android.os.AsyncTask.finish(AsyncTask.java:636)at android.os.AsyncTask.access $ 500 (AsyncTask.java:177)在android.os.Loper.loop(Looper。)的android.os.AsyncTask $ InternalHandler.handleMessage(AsyncTask.java:653)android.os.Handler.dispatchMessage(Handler.java:111)。 java:194)在android.app.ActivityThread.main(ActivityThread.java:5660)at java.lang.reflect.Method.invoke(Native Method)at j com.android.internal.os.ZygoteInit.main中的com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:963)中的ava.lang.reflect.Method.invoke(Method.java:372) ZygoteInit.java:758)

以下是我发送电子邮件的代码

  if (response.body().getStatus().equals("OK")) { snapManager.updateSnapStatus(AssetsManagementContract.SnapEntry.COLUMN_SITE_SNAP, snap.getSnapName(), Constants.SNAP_SYNCED); Intent broadcastSyc = new Intent(); broadcastSyc.setAction(Common.GetSyncImageAction()); broadcastSyc.putExtra("STATUS", true); mContext.sendBroadcast(broadcastSyc); sendImage(mContext); BackgroundMail.newBuilder(mContext) .withUsername("gmail id") .withPassword("pass") .withMailto("gmail id") .withType(BackgroundMail.TYPE_PLAIN) .withSubject("New Meter Installation") .withBody("Meter #" + msn + " is "+ com+ " and "+ status) .send(); } 

我该如何解决这个问题? 任何帮助将受到高度赞赏

注意:电子邮件是在提交表单时发送的,保存后我没有使用任何对话框。

Update 1下面是BackgroudMailer类函数

 public class SendEmailTask extends AsyncTask { private ProgressDialog progressDialog; public SendEmailTask() { //error onPostExecute(BackgroundMail.java:265) } protected void onPreExecute() { super.onPreExecute(); if(BackgroundMail.this.processVisibility) { this.progressDialog = new ProgressDialog(BackgroundMail.this.mContext); this.progressDialog.setMessage(BackgroundMail.this.sendingMessage); this.progressDialog.setCancelable(false); this.progressDialog.show(); } } protected Boolean doInBackground(String... arg0) { try { GmailSender sender = new GmailSender(BackgroundMail.this.username, BackgroundMail.this.password); if(!BackgroundMail.this.attachments.isEmpty()) { for(int i = 0; i < BackgroundMail.this.attachments.size(); ++i) { if(!((String)BackgroundMail.this.attachments.get(i)).isEmpty()) { sender.addAttachment((String)BackgroundMail.this.attachments.get(i)); } } } sender.sendMail(BackgroundMail.this.subject, BackgroundMail.this.body, BackgroundMail.this.username, BackgroundMail.this.mailto, BackgroundMail.this.type); } catch (Exception var4) { var4.printStackTrace(); return Boolean.valueOf(false); } return Boolean.valueOf(true); } protected void onPostExecute(Boolean result) { super.onPostExecute(result); if(BackgroundMail.this.processVisibility) { this.progressDialog.dismiss(); // error onPostExecute(BackgroundMail.java:302) if(result.booleanValue()) { if(!TextUtils.isEmpty(BackgroundMail.this.sendingMessageSuccess)) { Toast.makeText(BackgroundMail.this.mContext, BackgroundMail.this.sendingMessageSuccess, 0).show(); } if(BackgroundMail.this.onSuccessCallback != null) { BackgroundMail.this.onSuccessCallback.onSuccess(); } } else { if(!TextUtils.isEmpty(BackgroundMail.this.sendingMessageError)) { Toast.makeText(BackgroundMail.this.mContext, BackgroundMail.this.sendingMessageError, 0).show(); } if(BackgroundMail.this.onFailCallback != null) { BackgroundMail.this.onFailCallback.onFail(); } } } } } 

问题是我无法编辑文件被锁定。

在onPostExecute中,您关闭对话框而不检查它是否实际显示:

 this.progressDialog.dismiss(); 

为此添加一个isShowing检查(以及以防万一的空检查..)

 if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } 

另外我看到你对上下文使用静态引用。 这可能导致内存泄漏 ,但这只是一个侧面说明。