Y
Y
Yarik Mamaev2018-02-11 22:00:50
Android
Yarik Mamaev, 2018-02-11 22:00:50

Why is the app crashing??

package com.example.roman.geoguiz;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.view.View;

import android.widget.TextView;
import android.widget.Toast;

public class GuizActivity extends AppCompatActivity {

    private Button mTrueButton;
    private Button mFalseButton;
    private Button mNextButton;
    private TextView mTV;
    private int mCurrentIndex = 0;

    TrueFalse[] mQuesitonBank = new TrueFalse[]{
            new TrueFalse(R.string.onn, true),
            new TrueFalse(R.string.inn, true),
            new TrueFalse(R.string.gcc, true),
    };

    private void updeteQueation(){
        int question = mQuesitonBank[mCurrentIndex].getQuestion();
        mTV.setText(question);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guiz);

        mTV = (TextView) findViewById(R.id.TV);
        mTrueButton = (Button) findViewById(R.id.button_true);
        mFalseButton = (Button) findViewById(R.id.button_false);
        mNextButton = (Button) findViewById(R.id.button_next);

        mTrueButton.setOnClickListener(new View.OnClickListener(){
            public void onClick(View view){
                Toast.makeText(GuizActivity.this, R.string.correct_toast, Toast.LENGTH_SHORT).show();
            }
        });

        mFalseButton.setOnClickListener(new View.OnClickListener(){
            public void onClick(View view){
                Toast.makeText( GuizActivity.this, R.string.incorrect_toast, Toast.LENGTH_SHORT).show();
            }
        });

        mNextButton.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                mCurrentIndex = (mCurrentIndex++) % mQuesitonBank.length;
                updeteQueation();
            }

        });

        updeteQueation();

    }
    protected boolean onCreateOptionMeny(Menu menu){

        return true;
    }
}

package com.example.roman.geoguiz;

public class TrueFalse extends Object {
    private int mQuestion;

    private boolean mTrueQuestion;

    public TrueFalse (int question, boolean trueQuestion){
        mQuestion = question;
        mTrueQuestion = trueQuestion;
    }

    public boolean isTrueQuestion() {
        return mTrueQuestion;
    }

    public void setTrueQuestion(boolean trueQuestion) {
        mTrueQuestion = trueQuestion;
    }

    public int getQuestion() {
        return mQuestion;
    }

    public void setQuestion(int question) {
        mQuestion = question;
    }
}

The compiler does not give any errors, but the application crashes. Where is the error possible?
PS Testing on real device with API 23

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2018-02-11
@Conqueror3

java.lang.RuntimeException: Unable to start activity widget.TextView

Here is your error. Most likely here:
mTV = (TextView) findViewById(R.id.TV);
R.id.TV not TextView

Y
Yarik Mamaev, 2018-02-12
@Conqueror3

You are right, there is a mistake in these lines!! But now I can't figure out why there is an error? The thing is that R.id.TV is a TextView

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question