##For accepting a string from a EditText on clicking a button##
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//save button
//be notified when the button is clicked
saves=(Button)findViewById(R.id.save);
saves.setOnClickListener(onSave);
}
private View.OnClickListener onSave=new View.OnClickListener()
{
public void onClick(View v)
{
Restaurant r = new Restaurant();
EditText name=(EditText)findViewById(R.id.name_enter);
EditText address=(EditText)findViewById(R.id.address_enter);
r.setName(name.getText().toString());
r.setAddress(address.getText().toString());
}
};
}
问题是我的应用程序每次启动时都会崩溃。 logcat说错误在save.setOnClickListener(onSave)行中;
答案 0 :(得分:0)
更改了这一行
setContentView(R.layout.activity_main);
到
setContentView(R.layout.fragment_main);