Android- java.lang.IllegalArgumentException [英] Android- java.lang.IllegalArgumentException
问题描述
我已经看过这个问题。但无法弄清楚问题是什么。
我在我的 ImageSyncReciever
类中使用 BackgroundMail
在后台发送电子邮件。但是当发送电子邮件时我的应用程序崩溃,同时给我以下错误
I already have seen this question. But couldn't figure out what's the issue.
I am sending an email in background using BackgroundMail
in my ImageSyncReciever
class. But when email is sent my app crashes while giving me the below error
致命例外:主
流程:com.thumbsol。 accuratemobileassetsmanagament,PID:7480
java.lang.IllegalArgumentException:View = com.android.internal.policy.impl.PhoneWindow $ DecorView {300e55de VE .... R ..... I。 0,0-0,0}未附加到窗口管理器
在android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:434)
在android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:353 )
在android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:116)
在android.app.Dialog.dismissDialog(Dialog.java:382)
在android.app.Dialog。在com.c中解雇(Dialog.java:365)
reativityapps.gmailbackgroundlibrary.BackgroundMail $ SendEmailTask.onPostExecute(BackgroundMail.java:302)
at com.creativityapps.gmailbackgroundlibrary.BackgroundMail $ SendEmailTask.onPostExecute(BackgroundMail.java:265)
at android.os.AsyncTask。完成(AsyncTask.java:636)
在android.os.AsyncTask.access $ 500(AsyncTask.java:177)
在android.os.AsyncTask $ InternalHandler.handleMessage(AsyncTask.java:653)
在android.os.Handler.dispatchMessage(Handler.java:111)
在android.os.Looper.loop(Looper.java:194)
在android.app.ActivityThread.main(ActivityThread.java:5660)
at java.lang.reflect.Method.invoke(Native方法)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:963)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:758)
FATAL EXCEPTION: main Process: com.thumbsol.accuratemobileassetsmanagament, PID: 7480 java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{300e55de V.E..... R.....I. 0,0-0,0} not attached to window manager at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:434) at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:353) at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:116) at android.app.Dialog.dismissDialog(Dialog.java:382) at android.app.Dialog.dismiss(Dialog.java:365) at 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) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5660) 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:963) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:758)
以下是我的代码我是电子邮件
Below is my code in which I am sending the email
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();
}
如何解决此问题?任何帮助都将受到高度赞赏
How can i resolve this issue? Any help would be highly appreciated
注意:电子邮件是在提交表单时发送的,保存后我没有使用任何对话框。
Note: The email is sent when the form is submitted and after saving I am not using any dialog.
更新1
以下是 BackgroudMailer
类函数
public class SendEmailTask extends AsyncTask<String, Void, Boolean> {
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();
}
}
}
}
}
问题是我无法编辑它,因为文件被锁定。
The problem is I cannot edit it as the file is locked.
推荐答案
在onPostExecute中你解雇对话框没有检查它是否实际显示:
in onPostExecute you dismiss the dialog without checking if it is actually shown:
this.progressDialog.dismiss();
为此添加一个isShowing检查(以及以防万一的空检查)
add a check of isShowing for that (and a null-check just in case..)
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
此外,我看到您对上下文使用静态引用。那可以导致内存泄漏,但这只是一个侧面说明。
Also I see that you use static references to contexts. That can lead to memory leaks, but that is just a side note.
这篇关于Android- java.lang.IllegalArgumentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!