按下按钮后出错

这个问题在这里已经有了答案:

  • NullPointerException在onCreate()中访问视图12个答案

  • 试试这个代码

    Button button1 = (Button) findViewById(R.id.button1);
    button1.setOnClickListener(new View.OnClickListener() {
    
    public void onClick(View v) 
    {
     Toast.makeText(getApplicationContext(), "Button pressed.",Toast.LENGTH_LONG).show();  
    }
    });
    
    链接地址: http://www.djcxy.com/p/96819.html

    上一篇: Error after pressing a button

    下一篇: List all the images on android device