android.view.WindowManager$BadTokenException: Unable to add window, is your activity running?
i have a popup windows on my activity, my popup was working fine, untill i click on spinner it gives me an error as logcat said :
11-01 15:28:31.131: E/AndroidRuntime(10846): android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@41f56ec8 is not valid; is your activity running?
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.view.ViewRootImpl.setView(ViewRootImpl.java:692)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:345)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.view.Window$LocalWindowManager.addView(Window.java:556)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.widget.PopupWindow.invokePopup(PopupWindow.java:1013)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:922)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.widget.ListPopupWindow.show(ListPopupWindow.java:595)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.widget.Spinner$DropdownPopup.show(Spinner.java:983)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.widget.Spinner.performClick(Spinner.java:608)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.view.View$PerformClick.run(View.java:17337)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.os.Handler.handleCallback(Handler.java:615)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.os.Handler.dispatchMessage(Handler.java:92)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.os.Looper.loop(Looper.java:137)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.app.ActivityThread.main(ActivityThread.java:4895)
11-01 15:28:31.131: E/AndroidRuntime(10846): at java.lang.reflect.Method.invokeNative(Native Method)
11-01 15:28:31.131: E/AndroidRuntime(10846): at java.lang.reflect.Method.invoke(Method.java:511)
11-01 15:28:31.131: E/AndroidRuntime(10846): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
11-01 15:28:31.131: E/AndroidRuntime(10846): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
11-01 15:28:31.131: E/AndroidRuntime(10846): at dalvik.system.NativeStart.main(Native Method)
this is my code:
imgSearch.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// Intent cari= new Intent(MerchantSimasCard.this,Pencarian.class);
// startActivity(cari);
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View popupSet = inflater.inflate(R.layout.cari, null);
spin_all=(Spinner)popupSet.findViewById(R.id.spin_kategori);
spin_kota=(Spinner)popupSet.findViewById(R.id.spin_kota);
spin_abjad=(Spinner)popupSet.findViewById(R.id.spin_abjad);
search=(EditText)popupSet.findViewById(R.id.search);
buttonsearch=(Button)popupSet.findViewById(R.id.buttonsearch);
final PopupWindow pw = new PopupWindow(popupSet, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
new SpinnerKategori().execute();
buttonsearch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (ListMerchant.size()>0) {
ListMerchant.clear();
ListChildMerchantChild.clear();
}
String url1 = null;
try {
url1 = "http://www3.abc.co.id/";
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
pw.dismiss();
System.out.println(url1);
new TerbaruAsyncTask(url1).execute();
}
});
pw.showAtLocation(findViewById(R.id.merchantsimascard), Gravity.CENTER, 0, 0);
}
});
public class SpinnerKategori extends AsyncTask{
String url ="http://www3.sinarmasmsiglife.co.id/E-Policy/ios/sc_merchant.htm?s=1";
public SpinnerKategori(){
this.url=url;
}
@Override
protected void onPreExecute(){
super.onPreExecute();
dialog=ProgressDialog.show(MerchantSimasCard.this,"", "melakukan pengambilan data");
}
@Override
protected String doInBackground(Void... params) {
String result="";
try {
result=Connection.get(url);
}catch (Exception e){
result="";
}
return result;
}
@Override
protected void onPostExecute(String result){
super.onPostExecute(result);
ParsingCategory(result.replace("\n", "").trim());
ArrayAdapterspinnerMenu = new ArrayAdapter (MerchantSimasCard.this,R.layout.spinner_style, kategori);
spinnerMenu.setDropDownViewResource(R.layout.spinner_dropdown);
spin_all.setAdapter(spinnerMenu);
ArrayAdapterSpinnerKota = new ArrayAdapter (MerchantSimasCard.this, R.layout.spinner_style, kota);
SpinnerKota.setDropDownViewResource(R.layout.spinner_dropdown);
spin_kota.setAdapter(SpinnerKota);
ArrayAdapterSpinnerabjad= new ArrayAdapter (MerchantSimasCard.this,R.layout.spinner_style, abjad);
Spinnerabjad.setDropDownViewResource(R.layout.spinner_dropdown);
spin_abjad.setAdapter(Spinnerabjad);
dialog.dismiss();
}
}
private void ParsingCategory(String result) {
if (!result.equals("")) {
try {
JSONObject jsonObject = new JSONObject(result);
JSONArray cat = jsonObject.getJSONArray("cat");
for (int i=0; i
JSONObject status = cat.getJSONObject(i);
String Category=status.getString("name");
kategori.add(Category);
}
JSONArray city=jsonObject.getJSONArray("cit");
for (int j=0; j
String kot = (String) city.get(j);
kota.add(kot);
}
}
catch (Exception e) {
Log.d("TEST CHART", e.getMessage());
}
}
}
i have no idea to find my false, i hope there is someone can help me to solve my problem. thank you
Read more
stackoverflow.comm
No comments:
Post a Comment