java.lang.NullPointerException : displaying records from database in an expandable listview

前端 未结 1 1897
闹比i
闹比i 2021-01-23 03:46

As the question dictates, i need to display records from database, different record for each child.ie, child 1= record 1 data. child 2 =record 2 data.so and so. i came up with t

1条回答
  •  梦毁少年i
    2021-01-23 04:19

    It should be like below. Also post the stack trace so that we can help you further

    public class DisplayActivity extends ListActivity {
    DBAdapter db;
    @Override
    public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_cursor); 
     db=new DBAdapter(this);  
    Button viewbutton=(Button)findViewById(R.id.button2);
    viewbutton.setOnClickListener(new OnClickListener()
    {
           @override
           public void onClick(View v)
           {
                 // do something
           }   
    
    });
    }
    

    Edit:

    
    
      
    
      

    MainActivity.java

    public class MainActivity extends Activity {
    
        ListView lv;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Button b = (Button) findViewById(R.id.button1);
            lv= (ListView) findViewById(R.id.lv);
            b.setOnClickListener(new OnClickListener()
            {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    // set your adapter to listview here
                }
    
            });
        }
    }
    

    0 讨论(0)
提交回复
热议问题