Buju01.java第19行出错,空指针,发Buju01.java文件代码上来看看。

解决方案 »

  1.   

    package com.example.buju01;import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.LinearLayout;public class Buju01 extends Activity {
    int count=0;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.buju01);
            
            Button button = (Button) findViewById(R.layout.buju01); //获取按键控件
            
            button.setOnClickListener(new View.OnClickListener(){
             public void onClick(View v){
             LinearLayout ll = (LinearLayout)findViewById(R.id.lla); //获取线性布局对象
             String msg = Buju01.this.getResources().getString(R.string.button);
             Button tempbutton = new Button(Buju01.this);
             tempbutton.setText(msg+(++count));
             tempbutton.setWidth(80);
             ll.addView(tempbutton);
             }
            });
            
        }    @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.buju01, menu);
            return true;
        }
    }
      

  2.   

    请问是如何查看那logcat中的错误呢?重点看那些错误,谢谢!!
      

  3.   

    空指针了  下面 提升了 出现null的方法  19行
      

  4.   

    哥们!你的获取按钮的引用应该这么写Button button = (Button) findViewById(R.id.buju01);
      

  5.   

    这一行出错了,
    Button button = (Button) findViewById(R.layout.buju01);findViewById的括号里面应该是你的Button的ID号,而不布局文件名称。
      

  6.   

    楼上正解,有具体应该是Button button = (Button) findViewById(R.id. ).id后应该是你布局文件里的button的ID号