我在我的android应用程序中创建了一个警告框。但是第一次它正确显示。在第二次或第三次它意外关闭,请帮助我。
记录cat错误
03-20 05:55:27.865: E/AndroidRuntime(4793): Caused by: java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
03-20 05:55:31.055: E/WindowManager(4793): Activity com.caprabo.mst.mobpaz.cardapp.activities.OldReceipts has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{418e4990 V.E..... R.....ID 0,0-388,198} that was originally added here
03-20 05:55:31.055: E/WindowManager(4793): android.view.WindowLeaked: Activity com.caprabo.mst.mobpaz.cardapp.activities.OldReceipts has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{418e4990 V.E..... R.....ID 0,0-388,198} that was originally added here
03-20 05:55:31.055: E/WindowManager(4793): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:345)
03-20 05:55:31.055: E/WindowManager(4793): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:239)
03-20 05:55:31.055: E/WindowManager(4793): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
03-20 05:55:31.055: E/WindowManager(4793): at android.app.Dialog.show(Dialog.java:281)
03-20 05:55:31.055: E/WindowManager(4793): at com.caprabo.mst.mobpaz.cardapp.activities.OldReceipts.alerter(OldReceipts.java:1332)
03-20 05:55:31.055: E/WindowManager(4793): at com.caprabo.mst.mobpaz.cardapp.activities.OldReceipts$Range_Search_Result.onPostExecute(OldReceipts.java:1256)
03-20 05:55:31.055: E/WindowManager(4793): at com.caprabo.mst.mobpaz.cardapp.activities.OldReceipts$Range_Search_Result.onPostExecute(OldReceipts.java:1)
03-20 05:55:31.055: E/WindowManager(4793): at android.os.AsyncTask.finish(AsyncTask.java:631)
03-20 05:55:31.055: E/WindowManager(4793): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-20 05:55:31.055: E/WindowManager(4793): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
03-20 05:55:31.055: E/WindowManager(4793): at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 05:55:31.055: E/WindowManager(4793): at android.os.Looper.loop(Looper.java:137)
代码
private class Search_Result extends AsyncTask<Void,String,Integer>
{
String data;
WebService wsObj;
CommonFunctions cfObj;
AlertBox abObj;
Encryption enObj;
JSONObject jsObj;
String result="";
String encrypted_device_id;
ProgressDialog dialog;
int final_flag=0;
@Override
protected Integer doInBackground(Void... params) {
if(cfObj.isConnectingToInternet())
{
try
{
/*jsObj.put("deviceid",encrypted_device_id);
jsObj.put("date",extras.getString("date"));*/
data=URLEncoder.encode("deviceid","UTF-8") + "=" + URLEncoder.encode(encrypted_device_id,"UTF-8");
data+="&" + URLEncoder.encode("date","UTF-8") + "=" + URLEncoder.encode(extras.getString("date"),"UTF-8");
result=wsObj.getWebData(Connector.search_by_date_page, data);
System.out.println("date result"+result);
if(result==null||result=="")
{
final_flag=ecObj.server_response_no_response_error;
}
}
catch (Exception e) {
final_flag=ecObj.server_response_no_response_error;
}
if(final_flag!=ecObj.server_response_no_response_error)
{
publishProgress(getResources().getString(R.string.populating_list));
try
{
if(result!=null && result!="[]"&&result.compareToIgnoreCase("[]")!=0)
{
JSONArray Mainarray=new JSONArray(result);
JSONObject obj=Mainarray.getJSONObject(0);
int flag=obj.getInt("flag");
if(flag==0)
{
System.out.println("test6 search");
final_flag=ecObj.no_data_available_code;
}
else
{
JSONArray jsonArr1=Mainarray.getJSONArray(1);
String date[]=new String[jsonArr1.length()];
String newDate[]=new String[jsonArr1.length()];
String time[]=new String[jsonArr1.length()];
String elpoints[]=new String[jsonArr1.length()];
String amount[]=new String[jsonArr1.length()];
String transaction_id[]=new String[jsonArr1.length()];
Integer transaction_type[]=new Integer[jsonArr1.length()];
for(int i=0;i<jsonArr1.length();i++)
{
JSONObject json_data=jsonArr1.getJSONObject(i);
date[i]=json_data.getString("date");
//calling the function for Date Format
newDate[i]=cfObj.converDateFormate(date[i]);
time[i]=cfObj.converTimeFormat(date[i]);
elpoints[i]=json_data.getString("earnedpoints");
amount[i]=json_data.getString("amount");
transaction_id[i]=json_data.getString("transactionid");
transaction_type[i]=Integer.parseInt(json_data.getString("trantype"));
aldate.add(newDate[i]);
alamount.add(amount[i]);
altransaction_type.add(transaction_type[i]);
if(transaction_type[i]==1)
{
transaction_id[i]="-";
}
altransactionid.add(transaction_id[i]);
key_holder.putString("date"+i,newDate[i]);
key_holder.putString("time"+i,time[i]);
//Only for ccd this needs to be null. For other put the elpoints[i] instead of "-"
key_holder.putString("elpoints"+i,"-");
key_holder.putString("amount"+i,amount[i]);
key_holder.putString("transaction_id"+i,transaction_id[i]);
key_holder.putInt("trantype"+i,transaction_type[i]);
}
final_flag=ecObj.success_code;
}
}
else
{
System.out.println("test3 search");
final_flag=ecObj.no_data_available_code;
}
}
catch (Exception e) {
System.out.println("test4 search");
final_flag=ecObj.server_response_error;
}
}
}
else
{
final_flag=ecObj.internet_connectivity_error;
}
return final_flag;
}
@Override
protected void onCancelled() {
super.onCancelled();
activity_finisher();
}
@Override
protected void onPostExecute(Integer rs) {
super.onPostExecute(rs);
if(rs==ecObj.success_code)
{
set_up_search_result_display_table();
dialog.dismiss();
}
else
{
dialog.dismiss();
if(rs==ecObj.no_data_available_code)
{
//set_up_search_result_display_table();
alerter(getResources().getString(R.string.alert_title),getResources().getString(R.string.no_receipts_date));
}*
}
//Alert Box
public void alerter(String title,String msg)
{
AlertDialog.Builder builder = new AlertDialog.Builder(OldReceipts.this);
builder.setTitle(title);
//builder.setIcon(R.drawable.ic_launcher);
builder.setMessage(msg);
builder.setPositiveButton(OldReceipts.this.getResources().getString(R.string.Okay),new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
//finish();
}
});
AlertDialog alert = builder.create();
alert.show();
}*
答案 0 :(得分:2)
可能会发生这种情况,因为某处您手动关闭(调用 * .close()或类似的东西)您的数据源对象 - 无论它是什么,它可能是HTTP或数据库连接。因此,您将此对象置于某种CLOSED状态,并且您无法从此数据源重新查询信息。
当您关闭数据源时,这是一个非常典型的错误,但打算进一步反复使用它。
要避免这种情况,只需在数据源上调用 * .close()方法,当您不再需要它时。例如,来自活动的 onDestroy()方法。
答案非常一般,因为您没有提供有关代码的足够详细信息。
答案 1 :(得分:0)
我认为你的对话框没有像你泄漏对话框那样被忽视。 您需要调用dialog.dismiss()来关闭警报对话框。
if(dialog != null){
dialog.dismiss();
}