Android : getting NullPointerException for ImageView imag = (ImageView) findViewById(R.id.image)?

Check whether the resource which your laoding is available in your res folder or not.

Its there... in drawable – Abhinav Tyagi May 2 at 11:24.

It seems that you haven't specified android:id="@+id/image" in the imageview inside your layout Edit: I think the problem is you are using findViewById before the ListView in your ListActivity contains your custom_row which is who has the ImageView. Try doing setListAdapter before populateList().

It is there in R.layout. Custom_row_screen3 as – Abhinav Tyagi May 2 at 11:04 Post the code of screen3 layout if you can. Maybe you're using the findViewById method of the wrong view and it haven't the image inside.

– Rafaesp May 2 at 11:12 I can't post it right now... just joined this forum so there is 8 hr restriction... will try to post in parts – Abhinav Tyagi May 2 at 11:20 setListAdapter before populateList() --> not working :( – Abhinav Tyagi May 2 at 11:32.

In short: You should write a ListAdapter which draws the views in the list. You seem to use findViewById() on the wrong view/context (on the screen3 xml layout). An example containing a ListAdapter is available at the android developer site.

The getView() method should basically look something like this: public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (convertView == null) { v = LayoutInflater. From(parent.getContext()). Inflate(R.layout.

Row, null); } h = tasks. Get(i); if(h. Get("taskStatus").trim().

Equals("1")){ imag = (ImageView) v. FindViewById(R.id. Image); imag.

SetImageResource(R.drawable. Done); } else { // ... } return v; }.

Can you explain in detail. I am new to android :) – Abhinav Tyagi May 2 at 11:45.

PopulateList() runs before the ListView is rendered to the screen, so the custom_row_screen3 doesn't exist in the Activity. You could subclass SimpleAdapter and override getView() or setViewImage(), but I often find it simpler to anonymously implement a SimpleAdapter. ViewBinder and assign it with SimpleAdapter#setViewBinder().

In the ViewBinder, return false if the View that's passed in isn't an ImageView. If it is, you can use the map of data (passed in as an Object) to check the value of the "taskStatus" key. Make sure to do this before calling setListAdapter().Adapter.

SetViewBinder(new SimpleAdapter. ViewBinder () { @Override boolean setViewValue(View view, Object data, String textRepresentation) { if (!(view instanceof ImageView)) return false; String taskStatus = ((Map) data). Get("taskStatus").trim(); ((ImageView) view).

SetImageResource(taskStatus. Equals("1")?R.drawable. Done : R.drawable.

Not); } }).

Thanks for helping me out but its total confusion for me right now! I am a novice in android and not used Binders and all. – Abhinav Tyagi May 2 at 12:05 can you send me a link showing an example of your code?

– Abhinav Tyagi May 2 at 12:09 not working SimpleAdapter adapter = new SimpleAdapter(.....); adapter. SetViewBinder(new SimpleAdapter. ViewBinder () { @SuppressWarnings("unchecked") @Override public boolean setViewValue(View view, Object data, String textRepresentation) { if (!(view instanceof ImageView)) return false; String ts = ((HashMap) data).

Get("taskStatus").trim(); ((ImageView) view). SetImageResource(ts. Equals("1")?R.drawable.

Done :R.drawable. Not); return true; } }); populateList(); setListAdapter(adapter); – Abhinav Tyagi May 2 at 12:37 @Abhinav: by "not working", do you mean nothing is showing up, that an exception is thrown or that it doesn't compile? Also, try calling populateList() before creating SimpleAdapter – Mwanji Ezana May 2 at 13:19.

Thanks all of you You all all pointed me in right direction that my imageview is not pointing to my adapter I followed the steps as in devblogs.net/2011/01/04/custom-listview-... and it was working! Just needed to put my image in hashmap... I was banging my head to the wall!

In the ViewBinder, return false if the View that's passed in isn't an ImageView. If it is, you can use the map of data (passed in as an Object) to check the value of the "taskStatus" key. Make sure to do this before calling setListAdapter().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions