Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid : getting NullPointerException for ImageView imag = (ImageView) findViewById(R.id.image)
    text
    copied!<p>I am getting Null Pointer Exception for ImageView imag = (ImageView) findViewById(R.id.image). I have custome layout declared in <strong>R.layout.screen3</strong> with custome list declared in <strong>R.layout.custom_row_screen3</strong>. Each row has few tasks and depending on their status an image is shown to right of each row.</p> <p>Please guide me in getting this resolved as I am new to android.</p> <p>here is my code below :::</p> <pre><code>public class screen3 extends ListActivity{ final ArrayList&lt;HashMap&lt;String, String&gt;&gt; list = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); ... ... ... TextView tv; ImageView imag; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen3); System.out.println("Screen3"); ... ... ... SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.custom_row_screen3, new String[] { "tname","schedule", "note", "time"}, new int[] { R.id.text1Screen3task, R.id.text2Screen3task, R.id.text3Screen3task, R.id.text4Screen3task}); populateList(); setListAdapter(adapter); } public void populateList() { for(int i = 0; i &lt;numberOfTasks; i++) { HashMap&lt;String, String&gt; h = new HashMap&lt;String, String&gt;(); HashMap&lt;String, String&gt; hm = new HashMap&lt;String, String&gt;(); h = tasks.get(i); ... ... hm.put("tname", h.get("taskName")); hm.put("schedule", h.get("STime")+" - "+h.get("ETime")); if(h.get("taskStatus").trim().equals("1")){ imag = (ImageView) findViewById(R.id.image);// &lt;&lt;---- NULL RETURNED imag.setImageResource(R.drawable.done); ... ... } else{ imag = (ImageView) findViewById(R.id.image);// &lt;&lt;---- NULL RETURNED imag.setImageResource(R.drawable.not); ... ... } list.add(hm); } ... ... } </code></pre> <p><strong>screen3 xml</strong> </p> <pre><code>&lt;ListView android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#000000" android:drawSelectorOnTop="false"&gt; &lt;/ListView&gt; </code></pre> <p></p> <p><strong>custom_row_screen3 xml</strong> </p> <pre><code>&lt;LinearLayout android:orientation="vertical" android:layout_width="0dip" android:layout_weight="1" android:layout_height="wrap_content"&gt; &lt;TextView android:id="@+id/text1Screen3task" android:layout_width="wrap_content" android:layout_height="0dip" android:layout_weight="1" android:textSize="21sp" android:textStyle="bold" android:gravity="clip_horizontal" /&gt; &lt;TextView android:id="@+id/text2Screen3task" android:layout_width="wrap_content" android:layout_height="0dip" android:layout_weight="1" android:textSize="16sp" android:gravity="clip_horizontal" /&gt; &lt;TextView android:id="@+id/text3Screen3task" android:layout_width="wrap_content" android:layout_height="0dip" android:layout_weight="1" android:textSize="16sp" android:gravity="clip_horizontal" /&gt; &lt;TextView android:id="@+id/text4Screen3task" android:layout_width="wrap_content" android:layout_height="0dip" android:layout_weight="1" android:textSize="16sp" android:gravity="clip_horizontal" /&gt; &lt;/LinearLayout&gt; &lt;ImageView android:id="@+id/image" android:layout_width="wrap_content" android:paddingBottom="51dip" android:layout_height="wrap_content" android:layout_marginRight="16dip" /&gt; </code></pre> <p></p> <p>Thanks Abhinav Tyagi</p>
 

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