I am learning Android, and this is the first time I encounter unsolvable error (for me), so I decided to ask you guys. Sorry for the messy post.
I have been trying to assign the Button to receive clicks, but then every time I put in a setOnClickListener(this)
in my MainActivity.java, it crash.
public class MainActivity extends ActionBarActivity implements View.OnClickListener{
Button add_fragment_button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new Overview())
.commit();
}
add_fragment_button = (Button) findViewById(R.id.add_wallet_button);
//this line still work perfectly
add_fragment_button.setOnClickListener(this);
//crash here
}
This crash, I assume, cause by the setOnClickListener()
, because I have made sure that the R.id is correct.
Please help. And also, sorry for my English.
Edit: Ok, thanks to the helpful comments I found out that the button is on the 'Overview.xml'. I've fixed that but then it came to another problem. The fragment manager replace the Overview fragment with another one, but they both appear on the screen, overlaying each other.