#My App keeps crashing when I go to the view pages with no error

5 messages · Page 1 of 1 (latest)

remote oak
#
public class MainActivity extends AppCompatActivity {
//VARIABLES
EditText quest, ans;
Button createCard, viewCard;
TextView txtQuest, txtAns;
DBHandler dbHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//CREATE VARIABLES AND GET WIDGET ID
quest = findViewById(R.id.editQuestion);
ans = findViewById(R.id.editAnswer);
txtQuest = findViewById(R.id.txtQuest);
txtAns = findViewById(R.id.txtAns);
createCard = findViewById(R.id.btnCardCreate);
viewCard = findViewById(R.id.btnViewCard);
//CREATE DB HANDLER CLASS
dbHandler = new DBHandler(MainActivity.this);

createCard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String result_question = quest.getText().toString();
String result_answer = ans.getText().toString();
if (!result_question.isEmpty() && !result_answer.isEmpty()) {
//PASS DATA TO DB
dbHandler.q_a(result_question, result_answer);
Toast.makeText(MainActivity.this, "Question: " + result_question + "\nAnswer: " + result_answer, Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, "Card Saved",Toast.LENGTH_SHORT).show();
txtQuest.setText(null);
txtAns.setText(null);} else {
txtQuest.setText("Please Enter a Question");
txtAns.setText("Please enter a answer");}
//if 1 or the other is false set error message
if (!result_question.isEmpty() && result_answer.isEmpty()) {
//FALSE ENTRY TEXT
txtAns.setText("Please Enter a answer");
txtQuest.setText("");} else if (result_question.isEmpty() && !result_answer.isEmpty()) {
//FALSE ENTRY TEXT
txtQuest.setText("Please enter a question");
txtAns.setText("");}}});
viewCard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent view = new Intent(MainActivity.this, ViewCards.class);
startActivity(view);}});}}```
chilly tangleBOT
#

This post has been reserved for your question.

Hey @remote oak! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

steel bay
#

Did you try using a debugger?

chilly tangleBOT