//packagename imports ,variable
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//declaring views
lv_IFSC_.addFooterView(Btn_Load_More);
Btn_Load_More.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// Starting a new async task
new Asynctask_Record_List().execute();
}
});
final Handler handler = new Handler();
handler.post(new Runnable() {
public void run() {
try {
new Assign_task_Bank().execute();
} catch (Exception e) {
}
}
});
rel_main_logo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Handler handler = new Handler();
handler.post(new Runnable() {
public void run() {
try {
new Assign_task_Bank().execute();
} catch (Exception e) {
}
}
});
rel_Full_Advertise.setVisibility(View.VISIBLE);
rel_Full_IFSE_list.setVisibility(View.GONE);
spinner_State.setAdapter(null);
spinner_District.setAdapter(null);
spinner_City.setAdapter(null);
}
});
spinner_Bank.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View v, int position, long id) {
String txtNAME = ((TextView) v.findViewById(R.id.text_Name)).getText().toString();
String txtID = ((TextView) v.findViewById(R.id.text_ID)).getText().toString();
v.findViewById(R.id.text_URL)).getText().toString();
if(Integer.valueOf(txtID)==0)
{
Toast.makeText(getApplicationContext(),"please select Bank", Toast.LENGTH_SHORT).show();
}else
{
spinner_District.setAdapter(null);
spinner_City.setAdapter(null);
Str_Page_No=0;
Str_Select_Id=txtID;
Str_select_spinner_Bank=txtNAME;
try {
scroll_spinner.scrollTo(305, 1000);
} catch (Exception e) {
}
final Handler handler2 = new Handler();
handler2.post(new Runnable() {
public void run() {
try {
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB)
new Assign_Task_State().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,Str_select_spinner_Bank);
else
new Assign_Task_State().execute(Str_select_spinner_Bank);
} catch (Exception e) {
}
}
});
}
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
}
});
spinner_State.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View v, int position, long id) {
String txtNAME = ((TextView) v.findViewById(R.id.text_Name)).getText().toString();
String txtID = ((TextView) v.findViewById(R.id.text_ID)).getText().toString();
v.findViewById(R.id.text_URL)).getText().toString();
if(Integer.valueOf(txtID)==0)
{
Toast.makeText(getApplicationContext(),Str_select_spinner_Bank+"selected ,please select State", Toast.LENGTH_LONG).show();
}else
{
spinner_City.setAdapter(null);
Str_Select_Id=txtID;
Str_select_spinner_State=txtNAME;
try {
scroll_spinner.scrollTo(600, 1000);
} catch (Exception e) {
}
try {
Str_Page_No=0;
rel_Full_Advertise.setVisibility(View.GONE);
rel_Full_IFSE_list.setVisibility(View.VISIBLE);
final Handler handler3 = new Handler();
handler3.post(new Runnable() {
public void run() {
try {
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB)
new Asynctask_Record_List().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else
new Asynctask_Record_List().execute();
} catch (Exception e) {
}
}
});
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
}
});
lv_IFSC_.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
View v=arg1;
TextView txt_IFSC_L_Bank_value = (TextView) v.findViewById(R.id.txt_IFSC_L_Bank_value);
TextView txt_IFSC_L_ifsc_code_value = (TextView) v.findViewById(R.id.txt_IFSC_L_ifsc_code_value);
TextView txt_IFSC_micr_code_value = (TextView) v.findViewById(R.id.txt_IFSC_micr_code_value);
TextView txt_IFSC_branch_name_value = (TextView) v.findViewById(R.id.txt_IFSC_branch_name_value);
TextView txt_IFSC_contact_value = (TextView) v.findViewById(R.id.txt_IFSC_contact_value);
TextView txt_IFSC_address_value = (TextView) v.findViewById(R.id.txt_IFSC_address_value);
TextView txt_IFSC_Fax_value = (TextView) v.findViewById(R.id.txt_IFSC_Fax_value);
TextView txt_IFSC_city_value = (TextView) v.findViewById(R.id.txt_IFSC_city_value);
TextView txt_IFSC_district_value = (TextView) v.findViewById(R.id.txt_IFSC_district_value);
TextView txt_IFSC_state_value = (TextView) v.findViewById(R.id.txt_IFSC_state_value);
Intent tvintent = new Intent(getApplicationContext(),IFSC_List_Detail.class);
tvintent.putExtra("txt_IFSC_L_Bank_value", txt_IFSC_L_Bank_value.getText().toString());
tvintent.putExtra("txt_IFSC_L_ifsc_code_value", txt_IFSC_L_ifsc_code_value.getText().toString());
tvintent.putExtra("txt_IFSC_micr_code_value", txt_IFSC_micr_code_value.getText().toString());
tvintent.putExtra("txt_IFSC_branch_name_value", txt_IFSC_branch_name_value.getText().toString());
tvintent.putExtra("txt_IFSC_contact_value", txt_IFSC_contact_value.getText().toString());
tvintent.putExtra("txt_IFSC_address_value", txt_IFSC_address_value.getText().toString());
tvintent.putExtra("txt_IFSC_Fax_value", txt_IFSC_Fax_value.getText().toString());
tvintent.putExtra("txt_IFSC_city_value", txt_IFSC_city_value.getText().toString());
tvintent.putExtra("txt_IFSC_district_value", txt_IFSC_district_value.getText().toString());
tvintent.putExtra("txt_IFSC_state_value", txt_IFSC_state_value.getText().toString());
startActivity(tvintent);
}
});
class Assign_task_Bank extends AsyncTask<String, Void, String>{
String id;
private BufferedReader reader;
private StringBuffer readbuffer = new StringBuffer();
private ProgressDialog progress;
public Assign_task_Bank()
{
progress = new ProgressDialog(MainActivity.this);
progress.setCancelable(false);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
this.progress.setMessage("Please wait");
this.progress.show();
}
@Override
protected String doInBackground(String... params) {
try {
try{
MD_Spinner_id_name currentItem = null;
contents = new ArrayList<MD_Spinner_id_name>();
MD_Spinner_id_name Detail = new MD_Spinner_id_name();
Detail.setSpinner_ID(""+0);
Detail.setSpinner_Name("Bank...");
contents.add(Detail);
DataBaseHelper db = new DataBaseHelper(getApplicationContext()) ;
try {
db = new DataBaseHelper(getApplicationContext());
} catch (IOException e) {
e.printStackTrace();
}
String Select_Query="SELECT bank FROM MobileIFSCInfo GROUP BY bank ORDER BY bank ASC";
List<Contact> contacts = db.getAllContacts(Select_Query);
for (Contact cn : contacts) {
currentItem = new MD_Spinner_id_name();
currentItem.Spinner_ID=cn.Contact_ID;
currentItem.Spinner_Name=cn.Contact_NAME;
contents.add(currentItem);
}
db.close();
} catch (Exception e) {
}
finally {
if (reader != null) {
try {
reader.close();
} catch (Exception e) {
}
}
}
return readbuffer.toString();
} catch (Exception e) {
}
return readbuffer.toString();
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
try {
try {
adapter_Vehical_Category = new Adapter_Spinner_id_name(contents, getApplicationContext());
spinner_Bank.setAdapter(adapter_Vehical_Category);
} catch (Exception e) {
}
if (progress.isShowing()) {
progress.dismiss();
}
} catch (Exception e) {
}
}
}
class Assign_Task_State extends AsyncTask<String, Void, String>{
String id;
private BufferedReader reader;
private StringBuffer readbuffer = new StringBuffer();
private ProgressDialog progress;
public Assign_Task_State()
{
progress = new ProgressDialog(MainActivity.this);
progress.setCancelable(false);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
this.progress.setMessage("Please wait");
this.progress.show();
}
@Override
protected String doInBackground(String... params) {
try {
try{
MD_Spinner_id_name currentItem = null;
contents = new ArrayList<MD_Spinner_id_name>();
MD_Spinner_id_name Detail = new MD_Spinner_id_name();
Detail.setSpinner_ID(""+0);
Detail.setSpinner_Name("State");
contents.add(Detail);
DataBaseHelper db = new DataBaseHelper(getApplicationContext()) ;
try {
db = new DataBaseHelper(getApplicationContext());
} catch (IOException e) {
}
String Select_Query="SELECT state FROM MobileIFSCInfo WHERE lower(bank) = lower('"+Str_select_spinner_Bank+"') GROUP BY state ORDER BY state ASC";
List<Contact> contacts = db.getAllContacts(Select_Query);
for (Contact cn : contacts) {
currentItem = new MD_Spinner_id_name();
currentItem.Spinner_ID=cn.Contact_ID;
currentItem.Spinner_Name=cn.Contact_NAME;
contents.add(currentItem);
}
db.close();
} catch (Exception e) {
}
finally {
if (reader != null) {
try {
reader.close();
} catch (Exception e) {
}
}
}
return readbuffer.toString();
} catch (Exception e) {
}
return readbuffer.toString();
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
try {
try {
adapter_Vehical_Category = new Adapter_Spinner_id_name(contents, getApplicationContext());
spinner_State.setAdapter(adapter_Vehical_Category);
} catch (Exception e) {
}
if (progress.isShowing()) {
progress.dismiss();
}
} catch (Exception e) {
}
}
}
private Adapter_IFSC_RecordList adapter_IFSC;
private ArrayList<MD_Record_List> details= new ArrayList<MD_Record_List>();
class Asynctask_Record_List extends AsyncTask<String, String, String> {
private ProgressDialog pDialog;
private BufferedReader reader;
private StringBuffer readbuffer = new StringBuffer();
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Please Wait");
pDialog.show();
}
@Override
protected String doInBackground(String... params) {
details = new ArrayList<MD_Record_List>();
ConnectionDetector cd;
cd=new ConnectionDetector(getApplicationContext());
//----------------------------------------------------OFFLINE---------------------------------------------------
try {
DataBaseHendlerIFSC IFSCdb=new DataBaseHendlerIFSC(getApplicationContext());
details= (ArrayList<MD_Record_List>) IFSCdb.getAllContacts(//query );
} catch (IOException e) {
e.printStackTrace();
}
MD_Record_List Detail;
Detail = new MD_Record_List();
for(int i=0;i<details.size();i++){
if(Str_select_spinner_City=="")
{
if(Str_select_spinner_District=="")
{
if(Str_select_spinner_State=="")
{
if(Str_select_spinner_Bank=="")
break;
else if(details.get(i).bank==Str_select_spinner_Bank)
{
Detail=details.get(i);
String contact=Detail.contact;
String[] splited = contact.split("\\s+");
Log.e("0",""+splited[0]);
Log.e("1",""+splited[1]);
Log.e("2",""+splited[2]);
String strContact = "",strFax="";
String[] str_array =contact.split("Fax:");
strContact = str_array[0];
strFax = str_array[1];
Detail.setContact(strContact);
Detail.setFax(strFax);
continue;
}
}
else if(details.get(i).state==Str_select_spinner_State)
{
Detail=details.get(i);
String contact=Detail.contact;
String[] splited = contact.split("\\s+");
Log.e("0",""+splited[0]);
Log.e("1",""+splited[1]);
Log.e("2",""+splited[2]);
String strContact = "",strFax="";
String[] str_array =contact.split("Fax:");
strContact = str_array[0];
strFax = str_array[1];
Detail.setContact(strContact);
Detail.setFax(strFax);
continue;
}
}
else if(details.get(i).district==Str_select_spinner_District){
Detail=details.get(i);
String contact=Detail.contact;
String[] splited = contact.split("\\s+");
Log.e("0",""+splited[0]);
Log.e("1",""+splited[1]);
Log.e("2",""+splited[2]);
String strContact = "",strFax="";
String[] str_array =contact.split("Fax:");
strContact = str_array[0];
strFax = str_array[1];
Detail.setContact(strContact);
Detail.setFax(strFax);
continue;
}
}
else if(details.get(i).district==Str_select_spinner_City){
Detail=details.get(i);
String contact=Detail.contact;
String[] splited = contact.split("\\s+");
Log.e("0",""+splited[0]);
Log.e("1",""+splited[1]);
Log.e("2",""+splited[2]);
String strContact = "",strFax="";
String[] str_array =contact.split("Fax:");
strContact = str_array[0];
strFax = str_array[1];
Detail.setContact(strContact);
Detail.setFax(strFax);
continue;
}
}
details.clear();
details.add(Detail);
return readbuffer.toString();
}
protected void onPostExecute(String file_url) {
try {
if(Str_Page_No==0)
{
adapter_IFSC = new Adapter_IFSC_RecordList(details, getApplicationContext());
lv_IFSC_.setAdapter(adapter_IFSC);
}else
{
int currentPosition = lv_IFSC_.getFirstVisiblePosition();
adapter_IFSC = new Adapter_IFSC_RecordList(details,getApplicationContext());
lv_IFSC_.setAdapter(adapter_IFSC);
// Setting new scroll position
lv_IFSC_.setSelectionFromTop(currentPosition + 1, 0);
}
if (pDialog.isShowing()) {
pDialog.dismiss();
}
editText_Search.setText("");
} catch (Exception e) {
}
}
}
private void showToast(String msg) {
Toast.makeText(MainActivity.this,msg, Toast.LENGTH_LONG).show();
}
}
每当我在状态微调器中选择某些内容时,我的应用就会崩溃。
发现我的
doInBackground
函数未在Asynctask_Record_List
中执行。我知道这一点,因为没有显示第一行的吐司。我试图按照link中的说明进行更改,但没有结果。 Logcat显示窗口泄漏错误。
是
Asynctask
还是其他部分的问题?Logcat:
05-22 23:13:27.379: E/AndroidRuntime(8676): FATAL EXCEPTION: AsyncTask #3
05-22 23:13:27.379: E/AndroidRuntime(8676): java.lang.RuntimeException: An error occured while executing doInBackground()
05-22 23:13:27.379: E/AndroidRuntime(8676): at android.os.AsyncTask$3.done(AsyncTask.java:278)
05-22 23:13:27.379: E/AndroidRuntime(8676): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
05-22 23:13:27.379: E/AndroidRuntime(8676): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
05-22 23:13:27.379: E/AndroidRuntime(8676): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
05-22 23:13:27.379: E/AndroidRuntime(8676): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-22 23:13:27.379: E/AndroidRuntime(8676): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-22 23:13:27.379: E/AndroidRuntime(8676): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-22 23:13:27.379: E/AndroidRuntime(8676): at java.lang.Thread.run(Thread.java:856)
05-22 23:13:27.379: E/AndroidRuntime(8676): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
05-22 23:13:27.379: E/AndroidRuntime(8676): at com.takebestloan.DataBase.DataBaseHendlerIFSC.getAllContacts(DataBaseHendlerIFSC.java:167)
05-22 23:13:27.379: E/AndroidRuntime(8676): at com.takebestloan.IFSC.MainActivity$Asynctask_Record_List.doInBackground(MainActivity.java:1317)
05-22 23:13:27.379: E/AndroidRuntime(8676): at com.takebestloan.IFSC.MainActivity$Asynctask_Record_List.doInBackground(MainActivity.java:1)
05-22 23:13:27.379: E/AndroidRuntime(8676): at android.os.AsyncTask$2.call(AsyncTask.java:264)
05-22 23:13:27.379: E/AndroidRuntime(8676): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-22 23:13:27.379: E/AndroidRuntime(8676): ... 4 more
05-22 23:13:27.889: E/System(8676): Uncaught exception thrown by finalizer
05-22 23:13:27.889: E/System(8676): java.lang.IllegalStateException: Don't have database lock!
05-22 23:13:27.889: E/System(8676): at android.database.sqlite.SQLiteDatabase.verifyLockOwner(SQLiteDatabase.java:2223)
05-22 23:13:27.889: E/System(8676): at android.database.sqlite.SQLiteDatabase$1.entryRemoved(SQLiteDatabase.java:2315)
05-22 23:13:27.889: E/System(8676): at android.database.sqlite.SQLiteDatabase$1.entryRemoved(SQLiteDatabase.java:2311)
05-22 23:13:27.889: E/System(8676): at android.util.LruCache.trimToSize(LruCache.java:197)
05-22 23:13:27.889: E/System(8676): at android.util.LruCache.evictAll(LruCache.java:285)
05-22 23:13:27.889: E/System(8676): at android.database.sqlite.SQLiteDatabase.deallocCachedSqlStatements(SQLiteDatabase.java:2276)
05-22 23:13:27.889: E/System(8676): at android.database.sqlite.SQLiteDatabase.closeClosable(SQLiteDatabase.java:1248)
05-22 23:13:27.889: E/System(8676): at android.database.sqlite.SQLiteDatabase.finalize(SQLiteDatabase.java:2036)
05-22 23:13:27.889: E/System(8676): at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:185)
05-22 23:13:27.889: E/System(8676): at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:168)
05-22 23:13:27.889: E/System(8676): at java.lang.Thread.run(Thread.java:856)
05-22 23:13:37.319: E/WindowManager(8676): Activity com.takebestloan.IFSC.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@417cd8a0 that was originally added here
05-22 23:13:37.319: E/WindowManager(8676): android.view.WindowLeaked: Activity com.takebestloan.IFSC.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@417cd8a0 that was originally added here
05-22 23:13:37.319: E/WindowManager(8676): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:403)
05-22 23:13:37.319: E/WindowManager(8676): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
05-22 23:13:37.319: E/WindowManager(8676): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
05-22 23:13:37.319: E/WindowManager(8676): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
05-22 23:13:37.319: E/WindowManager(8676): at android.view.Window$LocalWindowManager.addView(Window.java:537)
05-22 23:13:37.319: E/WindowManager(8676): at android.app.Dialog.show(Dialog.java:278)
05-22 23:13:37.319: E/WindowManager(8676): at com.takebestloan.IFSC.MainActivity$Asynctask_Record_List.onPreExecute(MainActivity.java:1296)
05-22 23:13:37.319: E/WindowManager(8676): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
05-22 23:13:37.319: E/WindowManager(8676): at com.takebestloan.IFSC.MainActivity$7$1.run(MainActivity.java:428)
05-22 23:13:37.319: E/WindowManager(8676): at android.os.Handler.handleCallback(Handler.java:605)
05-22 23:13:37.319: E/WindowManager(8676): at android.os.Handler.dispatchMessage(Handler.java:92)
05-22 23:13:37.319: E/WindowManager(8676): at android.os.Looper.loop(Looper.java:137)
05-22 23:13:37.319: E/WindowManager(8676): at android.app.ActivityThread.main(ActivityThread.java:4517)
05-22 23:13:37.319: E/WindowManager(8676): at java.lang.reflect.Method.invokeNative(Native Method)
05-22 23:13:37.319: E/WindowManager(8676): at java.lang.reflect.Method.invoke(Method.java:511)
05-22 23:13:37.319: E/WindowManager(8676): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
05-22 23:13:37.319: E/WindowManager(8676): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
05-22 23:13:37.319: E/WindowManager(8676): at dalvik.system.NativeStart.main(Native Method)
最佳答案
评论这一行:
Toast.makeText(getApplicationContext(),"ListView Post", Toast.LENGTH_LONG).show();
您无法在doInBackground中更新用户界面-包括显示祝酒!
如果要在doInBackground()中检查中间结果,最好的选择是使用日志记录机制,例如log
Learn more about debugging here
关于android - AsyncTask不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30391648/