How to query the database of another activity in one activity in Android?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-06-19 09:07:44
0
1
890

//First
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;

//Second
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);
        
        
    }

Error message Null pointer exception

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(1)
三叔

First make sure there is a table 'school' in your database, then make sure this table has a field 'id''phone''name''address', and then make sure there is data in the table. You can judge after getting the cursor in the code If it is null, log it to see if it is null.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template