Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android-启动随机活动错误?_Java_Android_Debugging_Random_Android Activity - Fatal编程技术网

Java Android-启动随机活动错误?

Java Android-启动随机活动错误?,java,android,debugging,random,android-activity,Java,Android,Debugging,Random,Android Activity,我有5个不同的活动,每个活动都应该有一个随机数生成器,这样用户就可以进行随机活动 例如: 第一幕--->第一幕。3 第三幕--->第三幕。4 第二幕--->第二幕。5 注意:因此,从活动5开始,用户应该不能返回到以前的活动 这就是我在每个活动中写的,去随机活动,我做了一些变量,用户去的下一个活动,下一个活动将知道用户之前访问过的前一个活动。 这是用户将开始的第一个活动 public void on_quiz_1_wrong(View v){ score = score - 2;

我有5个不同的活动,每个活动都应该有一个随机数生成器,这样用户就可以进行随机活动

例如:
第一幕--->第一幕。3
第三幕--->第三幕。4
第二幕--->第二幕。5
注意:因此,从活动5开始,用户应该不能返回到以前的活动

这就是我在每个活动中写的,去随机活动,我做了一些变量,用户去的下一个活动,下一个活动将知道用户之前访问过的前一个活动。 这是用户将开始的第一个活动

public void on_quiz_1_wrong(View v){
     score =  score - 2;
     String visited = "1";
     txtScore.setText(String.valueOf(score) );
     int r1 = r.nextInt(4)+1;

     if(r1 == 1){
         Intent q1 = new Intent(this,Quiz_2.class);
         Bundle bundle1 = new Bundle();
         bundle1.putString("passVisit", visited);
         q1.putExtras(bundle1);
         q1.putExtra("passScore", score);
         startActivity(q1);
     }

     else if(r1 == 2){
         Intent q1 = new Intent(this,Quiz_3.class);
         Bundle bundle1 = new Bundle();
         bundle1.putString("passVisit", visited);
         q1.putExtras(bundle1);
         q1.putExtra("passScore", score);
         startActivity(q1);
     }

     else if(r1 == 3){
         Intent q1 = new Intent(this,Quiz_4.class);
         Bundle bundle1 = new Bundle();
         bundle1.putString("passVisit", visited); // visited = 1 ...> string value
         q1.putExtras(bundle1);
         q1.putExtra("passScore", score);
         startActivity(q1);
     }

     else if(r1 == 4){
         Intent q1 = new Intent(this,Quiz_5.class);
         Bundle bundle1 = new Bundle();
         bundle1.putString("passVisit", visited);
         q1.putExtras(bundle1);
         q1.putExtra("passScore", score);
         startActivity(q1);
     }
这是另一段代码,我把每个活动都放进去,所以现在活动知道上次访问,所以随机数生成器不应该在用户已经访问过的地方生成一个数字

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.quiz_3);

    txtScore = (TextView) findViewById(R.id.q_result);   // declaring the TextView 
    correctB = (Button) findViewById(R.id.quiz_3_correct);
    wrongB = (Button) findViewById(R.id.quiz_3_wrong);

    r = new Random();

    // Getting previous score
    Bundle extras = getIntent().getExtras(); 
    if (extras != null) 
     {
       score   = extras.getInt("passScore");
    }

    txtScore.setText(String.valueOf(score));

    Bundle getBundle = getIntent().getExtras();
    last_visit = getBundle.getString("passVisit"); // If previous was quiz 1 the---> last_visit is = 1



} // end of onCreate
如果用户希望从上一个活动中获得随机活动:

public void on_quiz_3_wrong(View v){
     score =  score - 2;
     String visited = "3";
     txtScore.setText(String.valueOf(score) );
     int r1 = r.nextInt(4)+1;

     if(r1 == 2 &&  !last_visit.equals("2") ){
         Intent q1 = new Intent(this,Quiz_2.class);
         Bundle bundle1 = new Bundle();
         bundle1.putString("passVisit", visited);
         q1.putExtras(bundle1);          
         q1.putExtra("passScore", score);
         startActivity(q1);
     }



     if(r1 == 4 && !last_visit.equals("4") ){
         Intent q1 = new Intent(this,Quiz_4.class);
         Bundle bundle1 = new Bundle();
         bundle1.putString("passVisit", visited);
         q1.putExtras(bundle1);
         q1.putExtra("passScore", score);
         startActivity(q1);
     }

     if(r1 == 5 &&  !last_visit.equals("5") ){
         Intent q1 = new Intent(this,Quiz_5.class);
         Bundle bundle1 = new Bundle();
         bundle1.putString("passVisit", visited);
         q1.putExtras(bundle1);
         q1.putExtra("passScore", score);
         startActivity(q1);

     }
}

我知道这很长,我很抱歉,但我试图给你尽可能多的细节,因为我知道这有点混乱

从九月份开始我就一直在努力工作,但仍然没有成功,我会很高兴的。
谢谢你

在进行以下任何其他活动之前,请尝试完成之前的所有活动:

 if(r1 == 1){
         Intent q1 = new Intent(this,Quiz_2.class);
         Bundle bundle1 = new Bundle();
         bundle1.putString("passVisit", visited);
         q1.putExtras(bundle1);
         q1.putExtra("passScore", score);
         startActivity(q1);
         finish();
     }

     else if(r1 == 2){
         Intent q1 = new Intent(this,Quiz_3.class);
         Bundle bundle1 = new Bundle();
         bundle1.putString("passVisit", visited);
         q1.putExtras(bundle1);
         q1.putExtra("passScore", score);
         startActivity(q1);
          finish();
     }

     else if(r1 == 3){
         Intent q1 = new Intent(this,Quiz_4.class);
         Bundle bundle1 = new Bundle();
         bundle1.putString("passVisit", visited); // visited = 1 ...> string value
         q1.putExtras(bundle1);
         q1.putExtra("passScore", score);
         startActivity(q1);
          finish();
     }

     else if(r1 == 4){
         Intent q1 = new Intent(this,Quiz_5.class);
         Bundle bundle1 = new Bundle();
         bundle1.putString("passVisit", visited);
         q1.putExtras(bundle1);
         q1.putExtra("passScore", score);
         startActivity(q1);
          finish();
     }

你到底有什么问题?应用程序是否崩溃,如果是,请发布stacktrace。什么工作不正常?你必须告诉我们实际的问题是什么,我不能轻易地浏览所有未格式化的代码。什么不起作用?首先,应用程序崩溃,即使崩溃消失,随机系统也无法工作@user2547460在执行任何其他活动之前,请尝试完成每个活动。@GrIsHu正确回答了这个问题:finish()将终止当前活动,如果不调用finish(),用户可以按back键返回到当前活动。有关这类活动的更多信息,请访问:但这不是后退箭头键,而是当用户单击on_Quike_3_错误按钮时,应用程序应将用户导航到一个新的活动,用户没有访问Yet您最好澄清您的问题您实际想要实现什么?@user2547460不要用您的日志修改我的答案。我接受了你的回答,请投票支持我的问题,因为现在我不能再问更多的问题了!对不起,我对你的问题的投票被锁定了。我现在不能投票。