目前是看得《安卓的第一行代码》,做到了button和Toast那儿就碰到了困难。
这样的问题
!!: The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new OnClickListener(){})
Maincode
public class FirstActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.first_layout);
Button button1 = (Button) findViewById(R.id.button_1);
button1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
Toast.makeTest(FirstActivity.this,"You have clicked Button 1",Toast.LENGTH_SHORT).show();
}
});
}
}
其实这个代码是没有问题的,在网上查找之后,是 包导入错误了。
这个问题出现是因为导错 包了 。
应该在开头中
import android.view.View.OnClickListener;
另外,开头中其实已经有了
import android.view.View;
所以说明这两个包其实并没有包含关系。
还有一个错误
Toast.makeTest(FirstActivity.this,"You have clicked Button 1",Toast.LENGTH_SHORT).show();
This part always shows an error.
Because it should be “makeText”, not the “makeTest”
And there is a tip: when you write a right submethod. it should be italic.
So happy to run this app successfully.