Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
    text
    copied!<p>I have created a custom Array adapter and i have image view and onclick of that image view i have am opening a Dialogue but it is showing me the <strong>android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application</strong> hers is my code</p> <p>the below line gives me error</p> <pre><code>if (context != null) { Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.spread_dialogue); dialog.setTitle("New Post"); dialog.show(); } public class Customfeedadapter extends ArrayAdapter&lt;Rowfeeds&gt; { Context context; Rowfeeds feeds; ViewHolder holder = null; ImageView imgview, likeimgview; Vector&lt;String&gt; mfeedid = new Vector&lt;String&gt;(); Vector&lt;String&gt; muserid = new Vector&lt;String&gt;(); public String guestlist; private ProgressDialog simpleWaitDialog; public String mssg; public String likemssg; Vector&lt;String&gt; mfeedlike = new Vector&lt;String&gt;(); Vector&lt;String&gt; mfeedspread = new Vector&lt;String&gt;(); Vector&lt;String&gt; mfeeddate = new Vector&lt;String&gt;(); Vector&lt;String&gt; mfeedtime = new Vector&lt;String&gt;(); private String likestrng, spreadstng, datestrng, timestrng; public Customfeedadapter(Context context, int resource, List&lt;Rowfeeds&gt; objects, Vector&lt;String&gt; feedIdvector, Vector&lt;String&gt; userIdvector, Vector&lt;String&gt; feedlikevector, Vector&lt;String&gt; feedspreadvector, Vector&lt;String&gt; feeddatevector, Vector&lt;String&gt; feedtimevector) { super(context, resource, objects); // TODO Auto-generated constructor stub this.context = context; this.mfeedid = feedIdvector; this.muserid = userIdvector; this.mfeedlike = feedlikevector; this.mfeedspread = feedspreadvector; this.mfeeddate = feeddatevector; this.mfeedtime = feedtimevector; } private class ViewHolder { TextView txtTitle; TextView txtDesc; TextView feedlike; TextView feedspread; TextView feeddate; TextView feedtime; } @Override public View getView(final int position, View convertView, final ViewGroup parent) { // TODO Auto-generated method stub try { feeds = getItem(position); LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); if (convertView == null) { convertView = mInflater.inflate(R.layout.feeds, null); holder = new ViewHolder(); // Log.i("imgvectr", ""+mfeedlike.elementAt(position)); likestrng = "" + mfeedlike.elementAt(position); spreadstng = "" + mfeedspread.elementAt(position); datestrng = "" + mfeeddate.elementAt(position); timestrng = "" + mfeedtime.elementAt(position); holder.txtTitle = (TextView) convertView.findViewById(R.id.textsimple); holder.txtDesc = (TextView) convertView.findViewById(R.id.showtime); holder.feedlike = (TextView) convertView.findViewById(R.id.feedlikes); holder.feedspread = (TextView) convertView.findViewById(R.id.textView1); holder.feeddate = (TextView) convertView.findViewById(R.id.feeddatetv); holder.feedtime = (TextView) convertView.findViewById(R.id.feedtime); } else //Log.v("else", "else"); { holder = (ViewHolder) convertView.getTag(); } holder.txtTitle.setTextColor(Color.BLACK); holder.txtDesc.setTextColor(Color.BLACK); //Log.v("getMfeedid", ""+feeds.getMfeedid()); holder.txtTitle.setText(feeds.getMsg()); holder.txtDesc.setText("~" + feeds.getUsrname()); holder.feedlike.setText(likestrng); holder.feedspread.setText(spreadstng + " Spreads"); holder.feeddate.setText(datestrng); holder.feedtime.setText(timestrng); } catch (Exception e) { // TODO Auto-generated catch block //Log.v("Exception", e.toString()); } // spread icon imgview = (ImageView) convertView.findViewById(R.id.imageView2); imgview.setTag(position); imgview.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //String strng = ""+getItem(position); try { //Toast.makeText(context,"hi",Toast.LENGTH_SHORT).show(); if (context != null) { Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.spread_dialogue); dialog.setTitle("New Post"); dialog.show(); } } catch (Exception e) { // TODO Auto-generated catch block Log.v("Exception", e.toString()); } /*Log.v("strng", ""+position); mfeedid.elementAt(position); Log.v("mfeedid.elementAt(position)", ""+mfeedid.elementAt(position)); String value = ""+mfeedid.elementAt(position); new SendApproveValue().execute(value.trim());*/ } }); likeimgview = (ImageView) convertView.findViewById(R.id.imageView1); likeimgview.setTag(position); likeimgview.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Log.v("strng", "" + position); mfeedid.elementAt(position); muserid.elementAt(position); Log.v("mfeedid.elementAt(position)", "" + mfeedid.elementAt(position)); Log.v("muserid.elementAt(position)", "" + muserid.elementAt(position)); String value = "" + mfeedid.elementAt(position); String value2 = "" + muserid.elementAt(position); new SendlikesValue().execute(value.trim(), value2.trim()); } }); return convertView; } private class SendApproveValue extends AsyncTask&lt;String, Void, String&gt; { @Override protected String doInBackground(String... param) { // TODO Auto-generated method stub Log.v("param", "= " + param[0]); String approvevalue = "" + param[0]; try { Log.i("spreadsInBackground", "spreadsInBackground"); HttpClient hc = new DefaultHttpClient(); HttpPost postMethod = new HttpPost("http://192.168.21.74/mynetwork/formapi/spreads"); List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(); nameValuePairs.add(new BasicNameValuePair("feed_id", approvevalue)); //nameValuePairs.add(new BasicNameValuePair("to", "5")); postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse rp = hc.execute(postMethod); if (rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { String result3 = EntityUtils.toString(rp.getEntity()); Log.v("spreads_data", "" + result3); JSONObject jobject = new JSONObject(result3); Log.v("msg", "" + jobject.getString("msg")); mssg = "" + jobject.getString("msg"); } else { Log.d("spreadsrJSON", "StatusCode " + rp.getStatusLine().getStatusCode()); } } catch (Exception e) { // TODO Auto-generated catch block Log.i("Exception", e.toString()); } return null; } @Override protected void onPreExecute() { Log.i("Async-Example", "onPreExecute Called"); //simpleWaitDialog = ProgressDialog.show(context,"Wait..", "Sending data"); } @Override protected void onPostExecute(String result) { Log.i("Async-Example", "onPostExecute Called"); Toast.makeText(context, mssg, Toast.LENGTH_SHORT).show(); //Toast.makeText(context,resultt,Toast.LENGTH_SHORT).show(); //RowItem3 item3 = new RowItem3(/*vector.elementAt(i),*/vector); //simpleWaitDialog.dismiss(); } } private class SendlikesValue extends AsyncTask&lt;String, Void, String&gt; { @Override protected String doInBackground(String... param) { // TODO Auto-generated method stub Log.v("param2", "= " + param[0]); Log.v("param2", "= " + param[1]); String approvevalue = "" + param[0]; String approvevalue2 = "" + param[1]; try { Log.i("SendlikesValue", "SendlikesValue"); HttpClient hc = new DefaultHttpClient(); HttpPost postMethod = new HttpPost("http://192.168.21.74/mynetwork/formapi/likes"); List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(); nameValuePairs.add(new BasicNameValuePair("feed_id", approvevalue)); nameValuePairs.add(new BasicNameValuePair("user_id", approvevalue2)); postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse rp = hc.execute(postMethod); if (rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { String result3 = EntityUtils.toString(rp.getEntity()); Log.v("likes_data", "" + result3); JSONObject jobject = new JSONObject(result3); Log.v("msg", "" + jobject.getString("msg")); likemssg = "" + jobject.getString("msg"); } else { Log.d("likesJSON", "StatusCode " + rp.getStatusLine().getStatusCode()); } } catch (Exception e) { // TODO Auto-generated catch block Log.i("likesException", e.toString()); } return null; } @Override protected void onPreExecute() { Log.i("Async-Example", "onPreExecute Called"); //simpleWaitDialog = ProgressDialog.show(context,"Wait..", "Sending data"); } @Override protected void onPostExecute(String result) { Log.i("Async-Example", "onPostExecute Called"); Toast.makeText(context, likemssg, Toast.LENGTH_SHORT).show(); //RowItem3 item3 = new RowItem3(/*vector.elementAt(i),*/vector); //simpleWaitDialog.dismiss(); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload