查找到错误了
可是,是照着视频写的为什么会错呢?
 protected void onCreate(Bundle savedInstanceState) {
 Button bt=(Button)findViewById(R.id.bt_call);
 bt.setOnClickListener(new MyListern());这边错了       
}
 class MyListern implements OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
EditText edit_number= (EditText)MainActivity.this.findViewById(R.id.edit_number);
String num=edit_number.getText().toString();

Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+num));
startActivity(intent);
}
    
    }

解决方案 »

  1.   

     bt.setOnClickListener(new MyListern());这边错了       这句空指针 说明 
    Button bt=(Button)findViewById(R.id.bt_call); 这句错了以我20年的经验来看,估计是你的 主 layout引用错了
      

  2.   

    查找到错误了
    可是,是照着视频写的为什么会错呢?
     protected void onCreate(Bundle savedInstanceState) {
     Button bt=(Button)findViewById(R.id.bt_call);
     bt.setOnClickListener(new MyListern());这边错了       
    }
     class MyListern implements OnClickListener{ @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    EditText edit_number= (EditText)MainActivity.this.findViewById(R.id.edit_number);
    String num=edit_number.getText().toString();

    Intent intent=new Intent();
    intent.setAction(Intent.ACTION_CALL);
    intent.setData(Uri.parse("tel:"+num));
    startActivity(intent);
    }
        
        }尝试把获取btn的代码要写在
    View rootView = inflater.inflate(R.layout.fragment_main, container,
                        false);
    的下面,并且这样写:
     btn = (Button)rootView.findViewById(R.id.btn);