//第一個
case R.id.selectId:
mmanager=(NotificationManager)this.getSystemService(NOTIFICATION_SERVICE);
Intent intent=new Intent(this, AllSchool.class);
PendingIntent pending=PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification notification=new Notification.Builder(this)
.setAutoCancel(true)
.setTicker("下拉查看")
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("学校")
.setContentText("详细信息")
.setContentIntent(pending)
.build();
mmanager.notify(1,notification);
break;
//第二個
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.manager);
listViewId=(ListView)findViewById(R.id.listViewId);
adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,contactList);
listViewId.setAdapter(adapter);
readManager();
}
public void readManager()
{
SQLiteDatabase db2=msh.getWritableDatabase();
Cursor cursor=db2.query("school", null, null, null, null, null, null);
if(cursor.moveToFirst())
{
int id=cursor.getInt(cursor.getColumnIndex("id"));
int phone=cursor.getInt(cursor.getColumnIndex("phone"));
String name=cursor.getString(cursor.getColumnIndex("name"));
String address=cursor.getString(cursor.getColumnIndex("address"));
//Log.d("MainActivity","id is"+id);
//Log.d("MainActivity","phone is"+phone);
//Log.d("MainActivity","name is"+name);
//Log.d("MainActivity","address is"+address);
contactList.add(id+"\n"+phone+"\n"+name+"\n"+address);
}
錯誤提示 空指標例外
首先確保你的資料庫中有'school'這個表,然後確定這個表有'id''phone''name''address'的字段,接著確定表中有數據,程式碼中可以在取得到cursor後判斷是否為null,打個Log看一下。