NullPointerException in TextView used in Alertdialog setView
<p><img src="http://i.stack.imgur.com/Pw8pM.png" alt="LOgCat..">In Android in litemitemclick I am using this piece of code:</p>

<pre><code>TextView tvofpostedText = (TextView)findViewById(R.id.postedgtext);
    @Override
                public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int pos,
                        long arg3) {



    final AlertDialog.Builder builder = new AlertDialog.Builder(
                        DemoPage2.this);
                LayoutInflater factory = LayoutInflater.from(DemoPage2.this);

                final View textEntryView = factory.inflate(
                        R.layout.layoutforalertdialog, null);

                // builder.setMessage("" + s.get(pos))
                try {
                    tvofpostedText.setText("username:" + s.get(pos));
                } catch (Exception e) {
                    // do nothing
                }
                builder.setMessage("" + username + (CharSequence) s.get(pos))
                        .setCancelable(true)
                        .setTitle("post Detail")
                        .setView(textEntryView)

                        .setPositiveButton("View Comments",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int id) {
                                        // ListViewActivity.this.finish();

                                    }
                                })
                        .setNegativeButton("Cancel",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int id) {
                                        dialog.cancel();
                                    }
                                })
                        .setNeutralButton("Post Comments",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int whichButton) {
                                    }
                                });
                AlertDialog alert = builder.create();
                alert.show();
                tvofpostedText.setText("username:" + s.get(pos));
            }

        });
</code></pre>

<p><strong>s</strong> is an <code>ArrayList</code>. I am getting a <code>NullPointerException</code> on the line <code>tvofpostedText.setText("username:" + s.get(pos));</code>. At least <em>"username"</em> should have been set as text even if <code>s.get(pos)</code> is null. Please help me out.In the logcat i am getting null pointer exception.tvofpostedText is comming null.Plese HELP></p>
