我正在学习如何构建应用程序,而我正在为绝对的初学者使用Android应用程序。在其中一个教程中,它要求我编写下面的代码,但是我收到错误:
setMessage(string) is undefined for the type MainActivity
现在代码的编写方式完全如书中所述。任何帮助将不胜感激,
public boolean onOptionsItemSelected(MenuItem Item) {
RelativeLayout bkgr = (RelativeLayout)findViewById(R.id.UiDesigns);
final
ImageView image=(ImageView)findViewById(R.id.imageView1);
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("Pick an Image!");
.setMessage("Please Select Image One or Image Two:")
.setCancelable(false)
.setPositiveButton("IMAGE 1", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
image.setImageResource(R.drawable.image1);
}
})
.setNegativeButton("IMAGE 2", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id){
image.setImageResource(R.drawable.image2);
}
});
答案 0 :(得分:2)
该行
builder.setTitle("Pick an Image!");
应该是:
builder.setTitle("Pick an Image!")
(no';'),以便下一行正确标记到它上面。