android编译错误“OnClickListener cannot be resolved to a type”解

在android代码编译时可能会出现如下错误:

部分代码:

 

[html]   view plain copy
  1. <</SPAN>span style="font-size:18px;">public void onCreate(Bundle savedInstanceState) {  
  2.         super.onCreate(savedInstanceState);  
  3.         setContentView(R.layout.addnew);  
  4.           
  5.         btn_img=(ImageButton) this.findViewById(R.id.btn_img);  
  6.         btn_img.setOnClickListener(new OnClickListener() {  
  7.               
  8.             public void onClick(View v) {  
  9.                 initImageChooseDialog();  
  10.                 imageChooseDialog.show();  
  11.             }  
  12.         });</</SPAN>span>  

 

错误提示:OnClickListener cannot be resolved to a type

解决方案:将语句btn_img.setOnClickListener(new OnClickListener(){···}中的OnClickListener改为View.OnClickListener即可

你可能感兴趣的:(android,编译错误,onclicklistener,cann)