我有一个MainActivity它增加了片段“A”,在片段“A”我送使用volley.I一些服务器的请求作出了被称为DialogUtil一类包含进度对话框implementation.Problem是,当我启动应用程序它显示在片段进度对话框实现 “A”。那是错误android在进度对话框中出错?
java.lang.IllegalArgumentException异常: 查看= com.android.internal.policy.impl.PhoneWindow $ {DecorView 42759d68 VE .... [R ...... D 0,0-456,144}不附加在窗口管理器上, 变得强制关闭。
DialogUtil类代码: -
public class DialogUtils {
public static ProgressDialog showProgressDialog(Context context, String message) {
ProgressDialog m_Dialog = new ProgressDialog(context);
m_Dialog.setMessage(message);
m_Dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
m_Dialog.setCancelable(false);
m_Dialog.show();
return m_Dialog;
}
}
进展片段 “A”
m_Dialog = DialogUtils.showProgressDialog(getContext(), "Loading...");
final String m_DealListingURL = "http://202.131.1.132:8080/ireward/rest/json/metallica/getDealListInJSON";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, m_DealListingURL, jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i(TAG, "Server Response:-" + response);
if (m_Dialog != null && m_Dialog.isShowing()) {
m_Dialog.dismiss();
}
相反的getContext的()通过getActivity() –
1。同样的问题。我也有每日5到10次的用户崩溃邮件的这个错误。我使用getActivity()但没有成功。 – user392117
嗨。 在片段中,您应该使用getActivity(),如上所述。 在我DialogUtils方法,我的第一行总是 如果(活动== NULL || activity.isFinishing())回报; 对话框在片段内使用时可以抛出NPE,如果它们被异步调用。 – Lev