Skip to content Skip to sidebar Skip to footer

What Can I Do About This Null Pointer Exception?

public class Display extends ListActivity { private ForumAdapter faHelper; private ProgressDialog dialog; private String Url; private int success = 0; priva

Solution 1:

setContentView(R.layout.something) put this first after write findviewbyid function then you will not find this null pointer exception

Solution 2:

If you are not using androids id for ListView you cannot extends the class by ListActivity you have to extend it with Activity.

You should use Androids id if you extend Class by ListActivity

android:id="@android:id/list

But if you are using android:id="@+id/dlist" then you have to extend class with Activity

Also you show use setContentView(R.layout.displaylist); before fetching the id

list = (ListView) findViewById(R.id.dlist);
        list.setOnItemClickListener(itemclicklistener());

Solution 3:

You need to call setContentView() before findViewById() or it will return null. Modify your code so it looks like this:

setContentView(R.layout.displaylist);

list = (ListView) findViewById(R.id.dlist);
list.setOnItemClickListener(itemclicklistener());

Post a Comment for "What Can I Do About This Null Pointer Exception?"