Error after pressing a button

This question already has an answer here:

  • NullPointerException accessing views in onCreate() 12 answers

  • 试试这个代码

    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/96820.html

    上一篇: Java中的本地方法是什么以及它们应该用在哪里?

    下一篇: 按下按钮后出错