On a menu item click, I want to pop a dialog box.
private void getAcLookUpDialog()
{
try
{
Dialog dlg = new Dialog(this);
dlg.setContentView(R.layout.aclookup);
dlg.setTitle(Html.fromHtml("<b><H2>" + "Select A/C # " + "</H2></b>" ));
startManagingCursor(cur);
cur = actable.getAllAC();
Log.d("Testing", "No of AC are " + cur.getCount());
ListView lv = (ListView) findViewById(R.id.aclookuplist);
SimpleCursorAdapter adapter1 = new SimpleCursorAdapter (this, R.layout.aclookup_listitem, cur, new String[] {"AC"}, new int[] {R.id.acactext});
lv.setAdapter(adapter1);
dlg.show();
}
catch(Exception e)
{
Log.d("Testing", "In getACLookUpdialog: error is: "+ e.toString());
}
}
It’s throwing
12-13 08:58:43.968: DEBUG/Testing(3563): In getACLookUpdialog: error is: java.lang.NullPointerException
The query is getting data. I tried to put diff query which is working in my other app.
aclookup.xml has a single listview.
aclookup_listitem has a single textview.
What am I doing wrong ?
First; when you have logged your errormessage with Log, call
e.printStackTrace()to get all the details of the exceptions (e.g. on what line it occurred).You get your error on
as
lvis null.I assume that the ListView exists in the dialog layout (R.layout.aclookup), so it is in the dialog you’ll want to search for the ListView: