Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid TextView and null pointer exception
    primarykey
    data
    text
    <p>In my activity I do</p> <pre><code>TextView bTitle = (TextView)findViewById(R.id.TextView); bTitle.setText(Html.fromHtml(title)); </code></pre> <p>where title is a string</p> <p>but i get a null pointer exception at second line ie. <strong>bTitle.setText(Html.fromHtml(title));</strong></p> <p>can anyone help???</p> <p><strong>Activity</strong></p> <pre><code>public class NewsDetails extends ListActivity{ public static final String LOG_TAG = "Infra"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listplaceholder); super.onStart(); Intent myIntent = getIntent(); String id = myIntent.getStringExtra("content_id"); String title = myIntent.getStringExtra("title"); //Spanned newTitle = Html.fromHtml(title); //tv.setText(Html.fromHtml(title)); TextView bTitle = (TextView)findViewById(R.id.TextView); Log.d(LOG_TAG, "What is the value: " + bTitle); bTitle.setText(Html.fromHtml(title)); ArrayList&lt;HashMap&lt;String, String&gt;&gt; mylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); String xml = XMLfunctions.getBodyXML(id); String result = xml.replaceAll("&lt;p&gt;", "&lt;p&gt;&lt;div align=\"justify\"&gt;"); String nXml = result.replaceAll("&lt;/p&gt;", "&lt;/div&gt;&lt;/p&gt;"); TextView body = (TextView)findViewById(R.id.TextView1); body.setText(Html.fromHtml(nXml)); //Spanned body = Html.fromHtml(nXml); /*HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); map.put("title", tv.toString()); map.put("news", tv1.toString()); mylist.add(map);*/ /*ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.list_item, new String[] { "title", "news" }, new int[] { R.id.item_title, R.id.item_subtitle }); setListAdapter(adapter); final ListView lv = getListView(); lv.setTextFilterEnabled(true);*/ } </code></pre> <p><strong>Layout - listplaceholder.xml</strong></p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;ListView android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:drawSelectorOnTop="false" /&gt; &lt;TextView android:id="@id/android:empty" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="No data" android:focusable="false" android:clickable="true"/&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>text_view.xml</strong></p> <pre><code>&lt;LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;TextView android:id="@+id/TextView" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="16px" android:textStyle="bold"&gt; &lt;/TextView&gt; &lt;TextView android:id="@+id/TextView1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="16px" android:textStyle="bold"&gt; &lt;/TextView&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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