Все сервисы Хабра
Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Закрыть
Задать вопрос
PeJlToFaN
0
вклад
1
вопрос
0
ответов
0%
решений
Комментарии
Информация
Ответы
Вопросы
Комментарии
Подписки
Нравится
Не понимаю в чем ошибка, не запускается MainActivity и SecondActivity?
PeJlToFaN
@PeJlToFaN
Автор вопроса
package com.example.myapplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import androidx.annotation.Nullable;
import java.util.Random;
public class SecondActivity extends Activity {
Button accept, nButton;
EditText question, answer;
ProgressBar progressBar;
private yQuiz Quiz = new yQuiz();
int x = 0;
Random r;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
accept.findViewById(R.id.accept);
question.findViewById(R.id.question);
answer.findViewById(R.id.answer);
progressBar.findViewById(R.id.progressBar);
nButton.findViewById(R.id.nbutton);
nButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SecondActivity.this, yLevelActivity.class);
startActivity(intent);
}
});
accept.setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
if(question.getText().length() != 0 && answer.getText().length() !=0 ){
Quiz.nQuestions[x] = String.valueOf(question.getText());
Quiz.nCorrectAnswer[x] = String.valueOf(answer.getText());
if(x==7) {
nButton.setVisibility(View.VISIBLE);
nButton.setClickable(true);
}
if(Integer.parseInt(Quiz.nCorrectAnswer[x])>=10 && Integer.parseInt(Quiz.nCorrectAnswer[x])<100){
Quiz.nChoices[x][0] = String.valueOf(r.nextInt()%100);
Quiz.nChoices[x][1] = String.valueOf(r.nextInt()%100);
Quiz.nChoices[x][2] = String.valueOf(answer.getText());
Quiz.nChoices[x][3] = String.valueOf(r.nextInt()%100);
}
else if(Integer.parseInt(Quiz.nCorrectAnswer[x])>=100 && Integer.parseInt(Quiz.nCorrectAnswer[x])<1000){
Quiz.nChoices[x][0] = String.valueOf(r.nextInt()%1000);
Quiz.nChoices[x][1] = String.valueOf(answer.getText());
Quiz.nChoices[x][2] = String.valueOf(r.nextInt()%1000);
Quiz.nChoices[x][3] = String.valueOf(r.nextInt()%1000);
}
else if(Integer.parseInt(Quiz.nCorrectAnswer[x])>=1000 && Integer.parseInt(Quiz.nCorrectAnswer[x])<10000){
Quiz.nChoices[x][0] = String.valueOf(r.nextInt()%10000);
Quiz.nChoices[x][1] = String.valueOf(r.nextInt()%10000);
Quiz.nChoices[x][2] = String.valueOf(r.nextInt()%10000);
Quiz.nChoices[x][3] = String.valueOf(answer.getText());
}
else if(Integer.parseInt(Quiz.nCorrectAnswer[x])>=10000 && Integer.parseInt(Quiz.nCorrectAnswer[x])<100000){
Quiz.nChoices[x][0] = String.valueOf(answer.getText());
Quiz.nChoices[x][1] = String.valueOf(r.nextInt()%100000);
Quiz.nChoices[x][2] = String.valueOf(r.nextInt()%100000);
Quiz.nChoices[x][3] = String.valueOf(r.nextInt()%100000);
}
else if(Integer.parseInt(Quiz.nCorrectAnswer[x])>=1 && Integer.parseInt(Quiz.nCorrectAnswer[x])<10){
Quiz.nChoices[x][0] = String.valueOf(answer.getText());
Quiz.nChoices[x][1] = String.valueOf(r.nextInt()%10);
Quiz.nChoices[x][2] = String.valueOf(r.nextInt()%10);
Quiz.nChoices[x][3] = String.valueOf(r.nextInt()%10);
}
x++;
progressBar.setProgress(x);
}
}
});
}
}
Написано
более трёх лет назад
Не понимаю в чем ошибка, не запускается MainActivity и SecondActivity?
PeJlToFaN
@PeJlToFaN
Автор вопроса
package com.example.myapplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends Activity {
Button l1, l2, l3, yl;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_one_more);
l1.findViewById(R.id.level1);
l2.findViewById(R.id.level2);
l3.findViewById(R.id.level3);
yl.findViewById(R.id.yourquiz);
l1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, OMActivity.class);
startActivity(intent);
}
});
l2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SLevelActivity.class);
startActivity(intent);
}
});
l3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ThLevelActivity.class);
startActivity(intent);
}
});
yl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, yLevelActivity.class);
startActivity(intent);
}
});
}
}
Написано
более трёх лет назад
Войдите на сайт
Чтобы задать вопрос и получить на него квалифицированный ответ.
Войти через центр авторизации
Закрыть
Реклама
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import androidx.annotation.Nullable;
import java.util.Random;
public class SecondActivity extends Activity {
Button accept, nButton;
EditText question, answer;
ProgressBar progressBar;
private yQuiz Quiz = new yQuiz();
int x = 0;
Random r;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
accept.findViewById(R.id.accept);
question.findViewById(R.id.question);
answer.findViewById(R.id.answer);
progressBar.findViewById(R.id.progressBar);
nButton.findViewById(R.id.nbutton);
nButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SecondActivity.this, yLevelActivity.class);
startActivity(intent);
}
});
accept.setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
if(question.getText().length() != 0 && answer.getText().length() !=0 ){
Quiz.nQuestions[x] = String.valueOf(question.getText());
Quiz.nCorrectAnswer[x] = String.valueOf(answer.getText());
if(x==7) {
nButton.setVisibility(View.VISIBLE);
nButton.setClickable(true);
}
if(Integer.parseInt(Quiz.nCorrectAnswer[x])>=10 && Integer.parseInt(Quiz.nCorrectAnswer[x])<100){
Quiz.nChoices[x][0] = String.valueOf(r.nextInt()%100);
Quiz.nChoices[x][1] = String.valueOf(r.nextInt()%100);
Quiz.nChoices[x][2] = String.valueOf(answer.getText());
Quiz.nChoices[x][3] = String.valueOf(r.nextInt()%100);
}
else if(Integer.parseInt(Quiz.nCorrectAnswer[x])>=100 && Integer.parseInt(Quiz.nCorrectAnswer[x])<1000){
Quiz.nChoices[x][0] = String.valueOf(r.nextInt()%1000);
Quiz.nChoices[x][1] = String.valueOf(answer.getText());
Quiz.nChoices[x][2] = String.valueOf(r.nextInt()%1000);
Quiz.nChoices[x][3] = String.valueOf(r.nextInt()%1000);
}
else if(Integer.parseInt(Quiz.nCorrectAnswer[x])>=1000 && Integer.parseInt(Quiz.nCorrectAnswer[x])<10000){
Quiz.nChoices[x][0] = String.valueOf(r.nextInt()%10000);
Quiz.nChoices[x][1] = String.valueOf(r.nextInt()%10000);
Quiz.nChoices[x][2] = String.valueOf(r.nextInt()%10000);
Quiz.nChoices[x][3] = String.valueOf(answer.getText());
}
else if(Integer.parseInt(Quiz.nCorrectAnswer[x])>=10000 && Integer.parseInt(Quiz.nCorrectAnswer[x])<100000){
Quiz.nChoices[x][0] = String.valueOf(answer.getText());
Quiz.nChoices[x][1] = String.valueOf(r.nextInt()%100000);
Quiz.nChoices[x][2] = String.valueOf(r.nextInt()%100000);
Quiz.nChoices[x][3] = String.valueOf(r.nextInt()%100000);
}
else if(Integer.parseInt(Quiz.nCorrectAnswer[x])>=1 && Integer.parseInt(Quiz.nCorrectAnswer[x])<10){
Quiz.nChoices[x][0] = String.valueOf(answer.getText());
Quiz.nChoices[x][1] = String.valueOf(r.nextInt()%10);
Quiz.nChoices[x][2] = String.valueOf(r.nextInt()%10);
Quiz.nChoices[x][3] = String.valueOf(r.nextInt()%10);
}
x++;
progressBar.setProgress(x);
}
}
});
}
}