Emulator not showing activity in android studio












0















When I run an emulator for my app, the emulator runs and android studio does not give me any errors. There is nothing highlighted for error in android studio. However, when the emulator runs, it does not load up my activity. The app that I am trying to run opens but it only shows a white screen.



I ran the debugger on my java file and it was ok. I wasn't able to step through the file since I cannot interact with the app since the activity won't load.



This is the java file:



public class MainActivity extends AppCompatActivity {
boolean check = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button green = (Button) findViewById(R.id.Green);
Button blue = (Button) findViewById(R.id.Blue);
Button red = (Button) findViewById(R.id.Red);
Button purple = (Button) findViewById(R.id.purple);
TextView Final = (TextView) findViewById(R.id.Score);
int score = 0;
do {
int pattern = new int[score + 1];
for (int i = 0;i<score + 1;i++) {
Random rand = new Random();
pattern[i] = rand.nextInt(4);

switch (pattern[i]) {
case 0:
green.setBackgroundColor(getColor(R.color.lightGreen));
SystemClock.sleep(1000);
case 1:
blue.setBackgroundColor(getColor(R.color.lightBlue));
SystemClock.sleep(1000);
case 2:
purple.setBackgroundColor(getColor(R.color.lightPurple));
SystemClock.sleep(1000);
case 3:
red.setBackgroundColor(getColor(R.color.lightRed));
SystemClock.sleep(1000);
}

}

final int clicks = {0};
final int guess= new int[score + 1];


while (clicks[0] < pattern.length) {
green.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
guess[clicks[0]] = 0;
clicks[0]++;
}
});
blue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
guess[clicks[0]] = 1;
clicks[0]++;
}
});

purple.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
guess[clicks[0]] = 2;
clicks[0]++;
}
});

red.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
guess[clicks[0]] = 3;
clicks[0]++;
}
});

}

if (!Arrays.equals(pattern,guess)) {
check = false;
score++;
}

}while (check);

String mark = "Your score is " + score;
Final.setText(mark);

}


}



This is the top and bottom part of the activity file:



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/View"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

[Code for other buttons/textviews]

</android.support.constraint.ConstraintLayout>









share|improve this question



























    0















    When I run an emulator for my app, the emulator runs and android studio does not give me any errors. There is nothing highlighted for error in android studio. However, when the emulator runs, it does not load up my activity. The app that I am trying to run opens but it only shows a white screen.



    I ran the debugger on my java file and it was ok. I wasn't able to step through the file since I cannot interact with the app since the activity won't load.



    This is the java file:



    public class MainActivity extends AppCompatActivity {
    boolean check = true;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button green = (Button) findViewById(R.id.Green);
    Button blue = (Button) findViewById(R.id.Blue);
    Button red = (Button) findViewById(R.id.Red);
    Button purple = (Button) findViewById(R.id.purple);
    TextView Final = (TextView) findViewById(R.id.Score);
    int score = 0;
    do {
    int pattern = new int[score + 1];
    for (int i = 0;i<score + 1;i++) {
    Random rand = new Random();
    pattern[i] = rand.nextInt(4);

    switch (pattern[i]) {
    case 0:
    green.setBackgroundColor(getColor(R.color.lightGreen));
    SystemClock.sleep(1000);
    case 1:
    blue.setBackgroundColor(getColor(R.color.lightBlue));
    SystemClock.sleep(1000);
    case 2:
    purple.setBackgroundColor(getColor(R.color.lightPurple));
    SystemClock.sleep(1000);
    case 3:
    red.setBackgroundColor(getColor(R.color.lightRed));
    SystemClock.sleep(1000);
    }

    }

    final int clicks = {0};
    final int guess= new int[score + 1];


    while (clicks[0] < pattern.length) {
    green.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    guess[clicks[0]] = 0;
    clicks[0]++;
    }
    });
    blue.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    guess[clicks[0]] = 1;
    clicks[0]++;
    }
    });

    purple.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    guess[clicks[0]] = 2;
    clicks[0]++;
    }
    });

    red.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    guess[clicks[0]] = 3;
    clicks[0]++;
    }
    });

    }

    if (!Arrays.equals(pattern,guess)) {
    check = false;
    score++;
    }

    }while (check);

    String mark = "Your score is " + score;
    Final.setText(mark);

    }


    }



    This is the top and bottom part of the activity file:



    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/View"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    [Code for other buttons/textviews]

    </android.support.constraint.ConstraintLayout>









    share|improve this question

























      0












      0








      0








      When I run an emulator for my app, the emulator runs and android studio does not give me any errors. There is nothing highlighted for error in android studio. However, when the emulator runs, it does not load up my activity. The app that I am trying to run opens but it only shows a white screen.



      I ran the debugger on my java file and it was ok. I wasn't able to step through the file since I cannot interact with the app since the activity won't load.



      This is the java file:



      public class MainActivity extends AppCompatActivity {
      boolean check = true;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      Button green = (Button) findViewById(R.id.Green);
      Button blue = (Button) findViewById(R.id.Blue);
      Button red = (Button) findViewById(R.id.Red);
      Button purple = (Button) findViewById(R.id.purple);
      TextView Final = (TextView) findViewById(R.id.Score);
      int score = 0;
      do {
      int pattern = new int[score + 1];
      for (int i = 0;i<score + 1;i++) {
      Random rand = new Random();
      pattern[i] = rand.nextInt(4);

      switch (pattern[i]) {
      case 0:
      green.setBackgroundColor(getColor(R.color.lightGreen));
      SystemClock.sleep(1000);
      case 1:
      blue.setBackgroundColor(getColor(R.color.lightBlue));
      SystemClock.sleep(1000);
      case 2:
      purple.setBackgroundColor(getColor(R.color.lightPurple));
      SystemClock.sleep(1000);
      case 3:
      red.setBackgroundColor(getColor(R.color.lightRed));
      SystemClock.sleep(1000);
      }

      }

      final int clicks = {0};
      final int guess= new int[score + 1];


      while (clicks[0] < pattern.length) {
      green.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      guess[clicks[0]] = 0;
      clicks[0]++;
      }
      });
      blue.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      guess[clicks[0]] = 1;
      clicks[0]++;
      }
      });

      purple.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      guess[clicks[0]] = 2;
      clicks[0]++;
      }
      });

      red.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      guess[clicks[0]] = 3;
      clicks[0]++;
      }
      });

      }

      if (!Arrays.equals(pattern,guess)) {
      check = false;
      score++;
      }

      }while (check);

      String mark = "Your score is " + score;
      Final.setText(mark);

      }


      }



      This is the top and bottom part of the activity file:



      <?xml version="1.0" encoding="utf-8"?>
      <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/View"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity">

      [Code for other buttons/textviews]

      </android.support.constraint.ConstraintLayout>









      share|improve this question














      When I run an emulator for my app, the emulator runs and android studio does not give me any errors. There is nothing highlighted for error in android studio. However, when the emulator runs, it does not load up my activity. The app that I am trying to run opens but it only shows a white screen.



      I ran the debugger on my java file and it was ok. I wasn't able to step through the file since I cannot interact with the app since the activity won't load.



      This is the java file:



      public class MainActivity extends AppCompatActivity {
      boolean check = true;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      Button green = (Button) findViewById(R.id.Green);
      Button blue = (Button) findViewById(R.id.Blue);
      Button red = (Button) findViewById(R.id.Red);
      Button purple = (Button) findViewById(R.id.purple);
      TextView Final = (TextView) findViewById(R.id.Score);
      int score = 0;
      do {
      int pattern = new int[score + 1];
      for (int i = 0;i<score + 1;i++) {
      Random rand = new Random();
      pattern[i] = rand.nextInt(4);

      switch (pattern[i]) {
      case 0:
      green.setBackgroundColor(getColor(R.color.lightGreen));
      SystemClock.sleep(1000);
      case 1:
      blue.setBackgroundColor(getColor(R.color.lightBlue));
      SystemClock.sleep(1000);
      case 2:
      purple.setBackgroundColor(getColor(R.color.lightPurple));
      SystemClock.sleep(1000);
      case 3:
      red.setBackgroundColor(getColor(R.color.lightRed));
      SystemClock.sleep(1000);
      }

      }

      final int clicks = {0};
      final int guess= new int[score + 1];


      while (clicks[0] < pattern.length) {
      green.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      guess[clicks[0]] = 0;
      clicks[0]++;
      }
      });
      blue.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      guess[clicks[0]] = 1;
      clicks[0]++;
      }
      });

      purple.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      guess[clicks[0]] = 2;
      clicks[0]++;
      }
      });

      red.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      guess[clicks[0]] = 3;
      clicks[0]++;
      }
      });

      }

      if (!Arrays.equals(pattern,guess)) {
      check = false;
      score++;
      }

      }while (check);

      String mark = "Your score is " + score;
      Final.setText(mark);

      }


      }



      This is the top and bottom part of the activity file:



      <?xml version="1.0" encoding="utf-8"?>
      <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/View"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity">

      [Code for other buttons/textviews]

      </android.support.constraint.ConstraintLayout>






      android-studio android-emulator






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 4:51









      GeraltGeralt

      265




      265
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001349%2femulator-not-showing-activity-in-android-studio%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001349%2femulator-not-showing-activity-in-android-studio%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          SQL update select statement

          'app-layout' is not a known element: how to share Component with different Modules