Голову сломал...Читаю и делаю все по книге Android для профессионалов 3 часть....Приложение из второй главы открывается и сразу закрывается, как в эмуляторе так и на реальном телефоне. Компилируется все нормально. Помогите пожалуйста ...
На телефоне выскакивает сообщение что приложение остановлено
package com.example.arterm.geoquiz;
public class Questions {
private int mTextResId;
private boolean mAnswerTrue;
public Questions(int mTextResId, boolean mAnswerTrue){
mTextResId=mTextResId;
mAnswerTrue=mAnswerTrue;
}
public int getTextResId() {
return mTextResId;
}
public void setTextResId(int textResId) {
mTextResId = textResId;
}
public boolean isAnswerTrue() {
return mAnswerTrue;
}
public void setAnswerTrue(boolean answerTrue) {
mAnswerTrue = answerTrue;
}
}
package com.example.arterm.geoquiz;
import android.app.admin.DevicePolicyManager;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class QuizActivity extends AppCompatActivity {
private Button mTrueButton;
private Button mFalseButton;
private Button mNextButton;
private TextView mQuestionTextView;
private Questions[] mQuestionsBank=new Questions[]{
new Questions(R.string.question_moscow,true),
new Questions(R.string.question_artem, true),
new Questions(R.string.question_irina, true),
new Questions(R.string.question_balosh,false),
};
private int mCurrentIndex=0;
public QuizActivity() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
mQuestionTextView=(TextView) findViewById(R.id.question_text_view);
mNextButton =(Button) findViewById(R.id.next_button);
mNextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCurrentIndex=(mCurrentIndex+1)%mQuestionsBank.length;
int question = mQuestionsBank[mCurrentIndex].getTextResId();
mQuestionTextView.setText(question);
}
});
mTrueButton= (Button) findViewById(R.id.true_button);
mTrueButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(QuizActivity.this,
R.string.correct_toast,
Toast.LENGTH_SHORT).show();
}
});
mFalseButton=(Button) findViewById(R.id.false_button);
mFalseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(QuizActivity.this,R.string.incorrect_toast,
Toast.LENGTH_SHORT).show();
}
});
mNextButton =(Button) findViewById(R.id.next_button);
mNextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCurrentIndex=(mCurrentIndex+1)%mQuestionsBank.length;
updateQuestion();
}
});
updateQuestion();
}
private void updateQuestion(){
int question = mQuestionsBank[mCurrentIndex].getTextResId();
mQuestionTextView.setText(question);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:id="@+id/question_text_view"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/true_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/true_button" />
<Button
android:id="@+id/false_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/false_button" />
</LinearLayout>
<Button
android:id="@+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/next_button" />
</LinearLayout>
<resources>
<string name="app_name">GeoQuiz</string>
<string name="question_moscow">Moscow is the capital of Russia?</string>
<string name="question_irina">Irina is the beutiful girl?</string>
<string name="question_artem">Arterm is the crazy?</string>
<string name="question_balosh">We are love Balashov?</string>
<string name="true_button">True</string>
<string name="false_button">False</string>
<string name="next_button">Next</string>
<string name="correct_toast">Correct!</string>
<string name="incorrect_toast">Incorrect</string>
</resources>