我正致力于呼叫阻止项目,现在我正在进行这项工作。我在列表视图中显示被阻止的短信。当我想删除任何消息时,它会给我一个警告对话框来删除它,现在当我点击它的按钮它将执行查询...然后在这一点上它崩溃了。 我不知道问题是什么。 这是我的代码。
public class BlockedSmsList extends Fragment {
ListView list;
private DbAdapterSmsLog mDbAdapter;
private ArrayList<String> numberList = null;
ArrayList<String> msgBody;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.block_backup, container,
false);
numberList = new ArrayList<String>();
msgBody = new ArrayList<String>();
mDbAdapter = new DbAdapterSmsLog(getActivity().getApplicationContext());
mDbAdapter.open();
list = (ListView) rootView.findViewById(R.id.call_block_listview);
displayLits();
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,final int pos,
long arg3) {
AlertDialog.Builder adb=new AlertDialog.Builder(getActivity());
adb.setTitle("Please Confirm");
adb.setMessage("Are you sure to delete?");
adb.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
mDbAdapter.deleteReminder(pos);
mDbAdapter.close();
displayLits();
}
});
adb.setNeutralButton("Cencel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
arg0.cancel();
}
});
adb.setNegativeButton("Delete All", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
mDbAdapter.deleteAllNumber();
mDbAdapter.close();
displayLits();
}
});
adb.show();
}
});
return rootView;
}
public void displayLits() {
Cursor c = mDbAdapter.fetchAllReminders();
numberList.clear();
c.moveToFirst();
if (c.moveToFirst()) {
while (c.isAfterLast() == false) {
String name = c.getString(c
.getColumnIndex(DbAdapterSmsLog.KEY_MODE));
String body = c.getString(c
.getColumnIndex(DbAdapterSmsLog.KEY_TITLE));
numberList.add(name);
msgBody.add(body);
c.moveToNext();
}
}
SmsCustomAdopter adapter=new SmsCustomAdopter(getActivity().getApplicationContext(), numberList,msgBody);
list.setAdapter(adapter);
}
}
答案 0 :(得分:0)
我从@shayan pourvatan评论中解决了我的问题。那是 “我认为你在mDbAdapter.fetchAllReminders()中得到了Exception;因为你在那行之前关闭了你的数据库。你已经关闭了mDbAdapter.close();删除那行,可能会解决你的问题,如果这对你不起作用发布日志猫。“