I have the following code and whenever I start to run it, it will display the message Unfortunately has stopped. It used to run before but now it is not. I have no errors in my program. Any idea what the problem might is pls? Below is my code:
Code in Main Activity:when button is clicked the message shows up unfortunately etc..
public class ContactsMain extends AppCompatActivity {
public static final int REQUEST_CODE_AddContact=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contacts_main);
Button b = (Button) findViewById(R.id.addContact);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View a) {
Intent i = new Intent(a.getContext(), AddContact.class);
startActivityForResult(i, REQUEST_CODE_AddContact);
}
});
}
}
Activity AddContact code:
package com.example.maria.maria_caruana_1bsc5;
public class AddContact extends AppCompatActivity {
public static final int REQUEST_CODE_ContactsMain=3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_add_contact);
Button b1 = (Button) findViewById(R.id.btnGoBack);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View d) {
Intent i = new Intent(d.getContext(), ContactsMain.class);
startActivityForResult(i, REQUEST_CODE_ContactsMain);
}
});
}
}